Derived Classes as Method Type

Derived Classes as Method Type

Old forum URL: forums.lhotka.net/forums/t/7295.aspx


RumbleCow posted on Friday, July 17, 2009

Trying to design an extensible object in which the RootParent class has two EditableChildList members (Rows/row, Columns/Column.  I want to define the EditableChildList and EditableChild classes as MustInherit such that the RootParent can accept any object derived from Rows/Row.  For example; Rows class inherits from BusinessListBase and defined as MustInherit.  Any object that was derived from this could be be used as the member in the RootParent.  As soon as I add the ‘MustInherit’ keyword I receive error indicated New cannot be used with.  I can derive from the ECL class (but can’t enforce) by declaring the constructor as friend but this seems to violate the factory method approach.  Is there another way?  I don't understand interfaces well enough to know if this is the way it would need to be done.

ajj3085 replied on Monday, July 20, 2009

What do you mean new? As in newing up your object:

Dim x = New MyMustInherit?

If that's the case... that's expected. You've created an abstract class, meaning it's now concidered only a partial implementation. A subclass must be created instead (which doesn't have the MustInherit). The factory method works by having something Newing the concrete class, but ONLY returning the abstract refernce... so you never know exactly which concerte type you'll get.

Does that help at all?

Copyright (c) Marimer LLC