lundi 22 juillet 2019

Decorator not implementing decorated interface

I have my small project where I wrapped object of one class with another class. Decorated class implements one interface but Decorator class does not implement it. I am curious whether it is still decorator pattern or some other pattern and "Decorator" class should be called Wrapper instead of Decorator in my project.

I have checked iluwatar github repository (https://github.com/iluwatar/java-design-patterns/tree/master/decorator/src/main/java/com/iluwatar/decorator) and tutorialspoint (https://www.tutorialspoint.com/design_pattern/decorator_pattern). For example in iluwatar there is: Decorator:

public class ClubbedTroll implements Troll

Decorated:

public class SimpleTroll implements Troll

In both cases (iluwatar and tutorialspoint) there is common interface implementation in decorator and decorated class. Does it mean it is mandatory to call it decorator design pattern?

Aucun commentaire:

Enregistrer un commentaire