the second option is often suitable alternative to multiple inheritance we can construct core objectand then create decorator around that core since the decorator object has the same interface as the core objectwe can even wrap the new object in other decorators here' how it looks in umlinterface +someaction(core decorator decorator +someaction(+someaction(+someaction(herecore and all the decorators implement specific interface the decorators maintain reference to another instance of that interface via composition when calledthe decorator does some added processing before or after calling its wrapped interface the wrapped object may be another decoratoror the core functionality while multiple decorators may wrap each otherthe object in the "centerof all those decorators provides the core functionality decorator example let' look at an example from network programming we'll be using tcp socket the socket send(method takes string of input bytes and outputs them to the receiving socket at the other end there are plenty of libraries that accept sockets and access this function to send data on the stream let' create such an objectit will be an interactive shell that waits for connection from client and then prompts the user for string responseimport socket def respond(client)response input("enter value"client send(bytes(response'utf ')client close(server socket socket(socket af_inetsocket sock_streamserver bind(('localhost', )server listen( trywhile true