Compound Patterns

A lot of patterns work together very well to form compound patterns. Below is a UML class diagram that implements various design patterns to form a compound pattern. After the diagram are some notes describing how and why this design was arrived at.

compound design patterns

 

  1. Polymorphism was introduced by the use of the Quackable interface. This makes a number of design patterns available to us.
  2. The decorator pattern is used to allow us to track the number of times the method quack() is called. Using the decorator pattern means we don't have to modify Duck and DuckCall
    • QuackDecorator implements Quackable so it can referenced as Quackable type
    • QuackDecorator has a Quackable instance variable so it can be passed a Quackable type
    • QuackDecorator is the first object in the chain, so it's quack() method is called first. This allows it to update a counter variable, then call the quack() of its Quackable instance variable
  3. To use the Goose class, the adapter pattern is utilised so that we can convert the call to Goose's honk() method to Quackables quack() method. Note that GooseAdapter implements Quackable so we can refer to all our objects as the same Quackable type.
  4. A factory pattern method is used to create our objects, so that we separate object creation from object use.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.