identical classes except inherit off different ancestor. Include file?identical classes except inherit off different ancestor. Include file?
Old forum URL: forums.lhotka.net/forums/t/3856.aspx
mtagliaf posted on Wednesday, November 07, 2007
I have these 2 CSLA classes that will be IDENTICAL except for the class they inherit off of:
Public Class ChildClassA
inherits ParentClassA <-- businessbase
end class
Public Class ChildClassB
inherits ParentClassB <-- businessbase
end class
the code inside childclassA and childclassB is 100% identical, except for the name of the class and the "inherits" line. I'm pretty sure that it will always be this way. (they won't diverge in the future, in fact, the divergence is maintained in the parent classes).
I don't want to simply copy/paste my code from one class to the other. The REAL answer is multiple inheritence, which isn't supported in VB.NET. Is there some sort of "include file" technology I could use to put code in one place and have it used in 2 classes? Do partial classes help at all here?
To pre-emptively answer any questions about reorganizing the classes, I can't do that here. I have the equivalent of the following class structure:
Person
Male
Man
Boy
Female
Woman
Girl
The code I want to share is in "Man" and "Boy" (and, later, "Woman" and "Girl"). If I reorganized classes so that "Adult" and "Child" were on the second level, then I would have the need to share code between "Man" and "Woman"
thanks
matt tag
Curelom replied on Wednesday, November 07, 2007
It sounds like the best thing to do is put the shared code in the Person class instead of Male or Female. Another option is to use an interface (or the VB version of an interface)Copyright (c) Marimer LLC