Decorator
About
To extend an object, without changing the original object implementation.
Is used for the
OofSOLID.Open to extension, Closed to modification.
Ex.: You make the
DecoratedComponentimplement the same interface as the object you want to extend. And in theDecoretedComponentconstructoryou pass the original component as an argument.
class DecoratedComponent implements SomeObject {
constructor (readonly obj: SomeObject) {
}
someFunc() {
[extendDoingMoreStuff]
...
return this.obj.func()
}
}, since middle kind of chains the layers in an array, and the decorators chains them kind of like recursively, one is inside of the other.
Last updated