Re: [chlor-develop] CSegment
Status: Pre-Alpha
Brought to you by:
lenny222
|
From: <chl...@li...> - 2006-03-17 07:46:32
|
chl...@li... wrote: > Hi, > >>>> I moved CSegment to a separate file and refactored the class a >>>> bit. I removed the inheritance on CGroup and replaced it by >>>> CObject for the time being. The CGroup interface allowed any >>>> CObject to be added to the CSegment, while only CNode objects >>>> should be allowed. This easily leads to hidden bugs, which are >>>> hard to track down and might stay hidden for a long time. >>> >>> >>> >>> I think we call isKindOfClass: everywhere to shut up warnings. >>> Anyway, why not. >> >> >> This is exactly my point, an object should be able to keep itself in >> a consistent state at all times. Runtime type verifications all over >> the code not only clutter the code but cause much more trouble than >> compile time type verifications. These refactorings will make future >> modifications easier. > > > I'm with you, using isKindOfClass: shows that your class hierarchy > offers room for improvement - but does this improvement always pay off? > Anyhow, I'm wondering whether CSegment and CGroup should have a more > concrete parent than CObject or not. Both have an identical instance > variable, shouldn't that one, and the methods for manipulating it, be > moved to a common parent (probably named CContainer)? > There are plenty of container classes in the standard libraries (e.g. NSMutableArray) which serve the purpose well enough. Changing the code is a lot easier when you don't have this big inheritance trees. This big inheritance trees make development a little bit easier on first development, but make it very hard change afterwards. We should be able to adapt the implementation of objects easily while leaving the interface as is. Use inheritance only for true inheritance (= implementation inheritance). To avoid copy/paste use composition. In the case of the segment : it's not because a segment contains nodes that it should be a container. In fact the purpose of a segment is to represent a line or curve segment, it's purpose is not to contain nodes. The kind of container used by the segment can be changed overtime while leaving the interface as is. This kind of changements are local to the object and won't affect the rest of the applications. OO design is exactly this : the ability changing implementation details while leaving the interface as is. Kind regards, Marc |