services.xmlwith the attribute
decoratespointing to our service we want to decorate. Next we have to add our service decorator as argument, but we append an
.innerto the end of the service to keep the old one as reference.
getDecorated()which has the return type of our instance.
ExampleServicewhich extends from our
AbstractExampleService. In our service the
getDecorated()function has to throw an
DecorationPatternExceptionbecause it has no decoration yet.
ExampleServiceDecoratorin this example. Our decorated service has to extend from the
AbstractExampleServiceand the constructor has to accept an instance of
AbstractExampleService. Furthermore, the
getDecorated()function has to return the decorated service passed into the constructor.
doSomethingNew()which first calls the
getDecorated()and then our new function
doSomethingNew()because if our decorator does not implement it yet, it will call it from the parent. The advantage of adding it as normal public function is that you can implement it step by step into your other services without any issues. After you have implemented the function in every service decorator, you can make it abstract for the next release. If you add it directly as an abstract function, you will get errors because the function is required for every service decorator.