[idpsg] - Decorator
BarraGialla.gif (2134 bytes)

Aggiornamento: 8 luglio 1999

domanda.gif (1131 bytes) Domanda di inizio

Domanda: Nella sezione Implementation del pattern Decorator, gli autori scrivono: "L'interfaccia di un oggetto decorator deve conformarsi all'interfaccia del componente che decora".

Si consideri ora un oggetto A, che è decorato da un oggetto B. Poichè l'oggetto B decora l'oggetto A, l'oggetto B condivide un'interfaccia con l'oggetto A. Se ad un qualche client viene passata un'istanza di tale oggetto decorato, ed un metodo tenta di chiamare un metodo in B che non è parte dell'interfaccia di A, ciò significa che l'oggetto non è più un Decorator, nel senso più stretto del pattern? Inoltre, perchè è importante che l'interfaccia di un oggetto decorator si conformi all'interfaccia del componente che decora?

(In the Implementation section of the Decorator Pattern, the authors write: A decorator object's interface must conform to the interface of the component it decorates.

Now consider an object A, that is decorated with an object B. Since object B "decorates" object A, object B shares an interface with object A. If some client is then passed an instance of this decorated object, and that method attempts to call a method in B that is not part of A's interface, does this mean that the object is no longer a Decorator, in the strict sense of the pattern? Furthermore, why is it important that a decorator object's interface conforms to the interface of the component it decorates?)