OOP question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I get the jist of this Inheritance stuff, I think, I'm just looking to
understand better...

I created a MustInherit base class with a constructor that had arguments.
Within the constructor method, the param values were mapped (or saved to)
module level PRIVATE variables. I decided on PRIVATE module variables over
PROTECTED because I reasoned that if I NEEDED to expose the module level
variables to the classes that inherited from my base class, I could do so
later. Until then, they were private.

I then created a subclass that had a constructor of its own. On this
constructor, I called, MyBase.New, which passed the param of the subclass's
constructor to the base class, so the base class could initialize itself.

One drawback of passing the sub class's constructor params to the base
class, I found, is this: The first line of the sub class had to be
MyBase.New, which meant, I could not add logic prior to this call to alter
or derive the parameter values before I pass them to the base class
constructor. This is probably atypical, although I got around the issue by
using a complex IIF statment within the My.New all.

My question is this: Someone suggested to me that I should have classed the
module level variables of my base class as protected and directly
initiatlized them from the sub class.

Is there a reason why one approach would be distinctively bette rthan the
other?


.



Relevant Pages

  • Re: Create objects using dynamic class names
    ... classes from a common base class and have an array of class references ... Not necessarily an open array, although that neatly coalesces the steps ... The constructor of the base class can only construct an instance of the ... TPageClass = class of TPage; ...
    (comp.lang.pascal.delphi.misc)
  • Re: Create objects using dynamic class names
    ... classes from a common base class and have an array of class references ... Not necessarily an open array, although that neatly coalesces the steps ... The constructor of the base class can only construct an instance of the ... TPageClass = class of TPage; ...
    (comp.lang.pascal.delphi.misc)
  • Re: What does the CLR do when you instantiate an object? - Continue
    ... I did think about looking at the rotor source but the original question ... asked was meant for the MS CLR not another implementation. ... > the complier will automaticaly insert the defaut constructor in the IL ... > The CLR WILL NOT call the base class automatically for you. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Factory method
    ... The base class must not create the children. ... If you don't want a public constructor, then define a Factory ... >I have an abstract class, and a set of classes that inherit from my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: copy contructor
    ... inheritance in Perl) it *has* an accessor. ... One of the tenets about Perl inheritance is "If you ... Sure it can have its own constructor. ... provided you call the base class' ...
    (comp.lang.perl.misc)