I had some engaging conversation with my co-worker and we've discussed the "proper way" of Decorator Pattern usage. Unfortunately I couldn't find any confirmation of my assumptions and it's the reason of how my question have begotten.
Let see:
- If we have
HandlerInterface
and alsoHandlerImpl
andDecoratorImpl
which both implements that interface, it's a decorator pattern? - But if our
HandlerInterface
contains many methods, and we want to decorate only some methods, we could use alsoAbstractDecorator
which implementsHandlerInterface
contract and some of its methods by default? - But what if we have only one implementation of
HandlerInterface
? May it become redundant in some use cases? Which could mean, we don't need an interface only for this and we could just replace usages ofHandlerInterface
withHandlerImpl
?. - And then our
AbstractDecorator
will not implementHandlerInterface
but extendHandlerImpl
instead. And if we would've done this. Why couldn't we just removeAbstractDecorator
and useHandlerImpl
directly in ourDecoratorImpl
as a contract? Maybe it's a bit far from the standard design, but as I understand, It's still a decorator pattern but after some modifications.
So, Is it a good way of thinking? Or maybe I'm missing something? Let me know. Thanks in advance.