Avoiding duplication in objects with large commonality
I am implementing an object structure which consists of a number of
objects and each of those objects should be accessed via a collection
class. For example:
Joints.Item("JointName").JointProperties
Pipes.Item("PipeName").PipeProperties
etc.
The properties in each of the collection classes are always very
similar - consisting of .Count and .Item (which returns a pointer to
the child object).
At the moment I have created a new class for each of the collections
and duplicated the collection code in each. This seems quite
inefficient and prone to mistakes if I ever decide to make a change to
the way I deal with collection objects.
Is there any neater way of doing this? I'm not sure whether I can do
anything with the "Implements" keyword but it looks like this is more
for creating a common interface rather than common base code.
Thanks a lot for your time,
Andrew
|