c# - No public members in abstract class -


i'm constructing code interacts http web service. interact it, invoke "commands" on it, either http requests or http post.

i want create base class (eg, servicecommand) encapsulates , hides httpwebrequest object, i'm not convinced want offer functionality publicly, subclasses.

subclasses (for example) searchcommand, or fetchcommand, , these use functionality offered protected methods in base class.

basically, question is: considered bad design create classes have protected members, , no public ones.

general questions ask myself design:

  • what class is. remember object oriented design objects. if creating new object need able think individual entity (at least abstractly). if providing functionality might better off creating interface or extension methods.
  • does functionality exist? no need create class wrap class worked well.
  • finally private versus public - if think subclasses need access base class values create protected member variable. variable work whether or not have public property in base class. once - if think value useful externally, can add get/set in base class. ends looking like:

    public abstract class baseclass {     protected object _member;     public object memberget { return _member; } }  public class inheritclass : baseclass {     // base class can "decide" set member or implement own set rules     public static void routinethatsetsmember(object value) { _member = value; } } 

i'm not sure if these rules uses maybe general design (or @ least keep conversation moving forward)!


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -