Our software represents each device as a concrete class. So let's say I have a class named Cpu-Version-1
, which is derived from a abstract baseclass called Device
. Now, the CPU vendor wants to release the economic version of this CPU ( Cpu-Version-2
), which is a feature reduced version of Cpu-Version-1
(obviously for a lower price ). 90% code of Cpu-Version-2
is same as of Cpu-Version-1
, but the remaining 10% code is no longer same. i.e. these are the features that have been removed in Cpu-Version-2
and so I should no longer represent it.
Now what would be the best way to design this class? I could inherit Cpu-Version-2
from Cpu-Version-1
(even though the inheritance is imperfect, since these two devices are peers). This would force me to override a lot of methods of cpu-version-1 to do nothing ( which looks ugly and somehow doesn't feel right). Also I don't think I could change the baseclass (Cpu-Version-1
or it's base) since the code is already in production and requires lot of approvals and justification. How would you make this design decision if you were me?
How do we make Cpu-Version-2
as much reusable and maintainable? Is there any OOP principles that you would follow? Or is it better tradeoff to take the easy wayout and override all the non-applicable methods of Cpu-Version-1
to do nothing? I code in object-oriented Perl.