In this snippet we have a class hierarchy with a SimpleMessage at the top. The SimpleMessage class has a constructor that accepts a content string as well as two methods: GetMessage; and, PrintMessage. Down the hierarchy we have three subclasses: ExcitedMessage; QuizzicalMessage; and, ExcitedAndQuizzicalMessage. The only difference in the subclasses is that they override the SimpleMessage constructor to change the content string and append various exclamations. When we instantiate various message objects, using the same content string, and iterate over them, each has their own unique output.
Historically, the painter was responsible for the mixing of the paint; keeping a ready supply of pigments, oils, thinners and driers. The painter would use his experience to determine a suitable mixture depending on the nature of the job. In modern times, the painter is primarily responsible for preparation of the surface to be painted, such as patching holes in drywall, using masking tape and other protection on surfaces not to be painted, applying the paint and then cleaning up.
In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, dynamically, without affecting the behavior of other objects from the same class. The decorator pattern is often useful for adhering to the Single Responsibility Principle, as it allows functionality to be divided between classes with unique areas of concern. The decorator pattern is structurally nearly identical to the chain of responsibility pattern, the difference being that in a chain of responsibility, exactly one of the classes handles the request, while for the decorator, all classes handle the request.
Categories: English 2-syllable wordsEnglish terms with IPA pronunciationEnglish terms with audio linksEnglish words suffixed with -er (agent noun)English terms derived from Middle FrenchEnglish lemmasEnglish nounsEnglish countable nounsEnglish terms with obsolete sensesen:NauticalAmerican EnglishEnglish agent nounsEnglish terms with multiple etymologiesen:Artistsen:People