How to refactor/rewrite an association into inheritance in the following example. Please see attached UML Minimal Example SellComputers (I am not allowed to embed pictures yet).
The UML Diagram describes the currently working state of my program. The real code structure is more complex so please excuse this made-up example.
There is a Market which initially holds some computers types in a list. When a computer is sold a new object SoldComputer is created and added to a second list. The sold computer references to the computer type. The CPU of the first computer sold can be called by:
soldComupter.ReferenceComputerType.CPU
Is it possible to replace the association with inheritance? Removing ReferenceComputerType and descant SoldComputer from ComputerType. A call would look like this:
soldComupter.CPU
The goal is not to disguise the reference by an decorator pattern but to descant all field and functionality by inheritance.
The problem i struggle with is, that multiple sold computer can reference the same computer type. So i cant typecast an existing computerType into a soldComputer as both list must exist at the same time in the real application.
Aucun commentaire:
Enregistrer un commentaire