delphi - What design pattern should I choose for different classes with common ancestor and common descendants? -
i'm refactoring of code @ moment. got 2 - redundant - units, 1 each product. both contain baseclass inherits few subclasses. these inherit more subclasses, well.
now want merge both units, redundant code won't redundant anymore , differing parts implemented separately in 2 different units.
i first thought of hierarchie following:
baseclass / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ product<a>baseclass product<b>baseclass \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / x /|\ / | \ / | \ / | \ / | \ / | \ / | \ / | \ / | \ / | \ / | \ / | \ / | \ subclass<1> subclass<2> subclass<3> / \ | / \ | / \ | / \ | / \ | / \ | / \ | subclass<1.1> subclass<1.2> subclass<3.1>
but problem x
, inheritance joins underneath product-specific classes, such inheritance isn't possible in delphi language.
so, think there has design pattern, useful implement such model common parent class , common descendant classes?
without seeing actual classes nor knowing trying achieve difficult give answer, because there many considerations.
true multiple inheritance of c++ not possible. can similar interfaces not seem appropriate here because have not indicated classes derive solely or b, if implemented them have move actual function definitions x anyway.
but x? consider logically. if is, say, fruit , b round , x orange, ngln says need merge , b x, (or baseclass) , throw , b away.
on other hand if were, petrol tank, b headlight , x car, x contain 2 class members , b, , subclasses reference members.
on third hand if there classes derived solely , solely b may choose use interfaces , live fact implementations may have duplicated in descendants of (and separately in b) , in x, or, perhaps equivalently, derive x baseclass , duplicate functions of b , c in x. neither of these last 2 options ideal, , may choose merge them anyway , derive x regardless of if or b.
Comments
Post a Comment