?
=?iso-8859-1?q?Erik_Wikstr=F6m?=
I'm working on a project where I need a couple of classes that purely
conceptually are related to each other such that I could create a
base-class and have a is-a relation between each of the classes and the
base-class. However each class is also extremely specialized for a
special purpose and there should be few if any instances where one
would be able to exchange one class for another, due to their very
specialized nature.
Further more, if I did create a common base-class it would either have
to be very minimal giving me only virtual functions for the most
trivial ones, or I could mandate a specific interface that each class
have to follow but that would require lots of extra work, since I would
then have to implement functions in some classes that will never
(should never even) be used and lose out on some optimization-points
(performance is of great importance and these classes (containers
holding up to millions of elements) are right in the critical path).
Either way (small base-class or large) there won't be much code that
can be put in the base-class since they are all so different on the
inside.
Currently I'm using template-functions in all cases where more than one
class can be used as a reference and it's working fine. It even
allowing me more freedom since I'm not bound to have the same
return-type on a method in one class as in another (I can use
proxy-objects), which would not be possible with inheritance, unless
the base-class was very small.
The only problem is that deep inside there is a voice (brought up on
Java) telling me that this would make a great class-hierarchy. Someone
with more wisdom than me, please help me, how far from the OO-path is
one allowed to stray for the sake of efficiency and ease of
programming?
conceptually are related to each other such that I could create a
base-class and have a is-a relation between each of the classes and the
base-class. However each class is also extremely specialized for a
special purpose and there should be few if any instances where one
would be able to exchange one class for another, due to their very
specialized nature.
Further more, if I did create a common base-class it would either have
to be very minimal giving me only virtual functions for the most
trivial ones, or I could mandate a specific interface that each class
have to follow but that would require lots of extra work, since I would
then have to implement functions in some classes that will never
(should never even) be used and lose out on some optimization-points
(performance is of great importance and these classes (containers
holding up to millions of elements) are right in the critical path).
Either way (small base-class or large) there won't be much code that
can be put in the base-class since they are all so different on the
inside.
Currently I'm using template-functions in all cases where more than one
class can be used as a reference and it's working fine. It even
allowing me more freedom since I'm not bound to have the same
return-type on a method in one class as in another (I can use
proxy-objects), which would not be possible with inheritance, unless
the base-class was very small.
The only problem is that deep inside there is a voice (brought up on
Java) telling me that this would make a great class-hierarchy. Someone
with more wisdom than me, please help me, how far from the OO-path is
one allowed to stray for the sake of efficiency and ease of
programming?