We have a parent class – Platform. All the specific device class are inherited from this parent Class – Device1, Device2, ….. DeviceN.
Based on the device input, we create an object of the respective Device class and work accordingly.
Few things which I observed in this code is the handling of device specific behavior in the base class (Platform class). Example,
function doSomething
{
initiateSomething();
.
if ($base->getPlatform() eq 'Device1')
{
........
}
startSomething();
doneSomething();
}
This type of conditional device specific code is spreaded over various places in the parent class. This code is specific to Device1 and not applicable for other devices. I thought of putting this device specific code in Device1 class as a function and calling it here, but that also did not work. Because this function is implemented only for Device1, so running this code for other Devices fails.
Your help will be highly appreciated.
You can implement this by having specific hooks for pre/post calls of your functions: