mardi 9 janvier 2018

Decorator Design Pattern tied to same interface

I have one slight issue with the decorator design pattern. It seems that the decorated objects are tied to the same interface as a standard non-decorated object.

Please see the example of the website line below. http://ift.tt/2rDgLqW

In this example the RedShapeDecorator is tied to the shape interface so both the RedShapeDecorator and a standard Circle object can only call the draw() method.

Well what do I do when I want my decorated object to be able to call more then draw(). What if I want my decorated object to have methods like drawBlackAndWhite() and draw3D() both of which are not appropriate to wrap up in the draw() method.

In other words I want to be able to extend the RedShapeDecorator to do the following..

redShapeDecorator.draw()
redShapeDecorator.drawBlackAndWhite();
redShapeDecorator.draw3D();

But the Shape interaface is limiting me to only calling redShapeDecorator.draw(). How do I solve this?

Aucun commentaire:

Enregistrer un commentaire