This question is language-agnostic for OOP languages.
I have two classes: DeviceA
and DeviceB
, which inherit from model class Device
. I need to implement two services DeviceAService
and DeviceBService
, which inherit from DeviceService
. My language does not support generics and I need to implement methods with a Device
parameter in DeviceService
, that will be overloaded in DeviceAService
and DeviceBService
and implemented differently according to the type of the Device
. Then I want to call these functions from the generic DeviceService
.
What is the best practice to design this? Is the use of if
and check on class type non-avoidable here? Another idea to optimally realize this design?
Aucun commentaire:
Enregistrer un commentaire