views:

64

answers:

1

I have two classes LightA and LightB. I have the source code of LightB but not that of LightA. I extended LightB with LightDimDip. ie LightDimDip:extends LightB. Now I need to apply DimDip feature to lightB also.

Can any one suggest good OOP design.

Once again I remind you people that I cannot modify LightA.

+2  A: 

Do the lights have a common interface? In which case I guess you could use the decorator pattern here

interface ILight { int GetIntensity() }
class LightA : ILight { int GetIntentisy(){ return 10; } }
class LightB : ILight { int GetIntensity(){ return 15; } }

class DimLight : ILight {
     public DimLight(ILight inner){}

     //Add behaviour inner
     int GetIntensity(){ return inner.GetIntensity() / 2; }
}

ILight dimLightA = new DimLight(new LightA())
ILight dimLightB = new DimLight(new LightB())

Then you can put the light behaviour in the DimLight class and apply it to any class which implements ILight.

amarsuperstar
The question says that the LightA class is not modifiable at this point.
Srikanth Venugopalan
@Whiskey-Tango-Foxtrot which is why I asked if there was a common interface in the first line of the response.
amarsuperstar
I have a root class (NSobject)
shakthi