Category Archives: Design Patterns

Mozart and the Flyweight Design Pattern

One of the few (mostly) true stories presented in Peter Schaffer‘s play and movie Amadeus was when Emperor Joseph II told Mozart that his latest work (Der Entführung aus dem Serail ) had “too many notes.” How many notes is too many? Mozart had a great answer. What would a Note class look like? Here [...]

Posted in Design Patterns | Tagged , | Leave a comment

Varying behavior of individual objects : Decorator Design Pattern

Let’s take a look at a class for a Baseball player. In this example I made it an abstract class but it could just as well have been an interface for this discussion. 1 2 3 4 public abstract class Player { public abstract void swing(); } } And here is an implementation class. 1 [...]

Posted in Design Patterns | Tagged , | Leave a comment

Factory Design Pattern

Let say we have some Pet domain classes. Pet is an interface which is implemented by Cat and Bird. Nothing more complicated than that for now. Of course you can always say: 1 Pet giacomo = new Cat(); This does indeed work. But let’s say you just want a Pet and you don’t really care [...]

Posted in Design Patterns | Tagged , , , | 1 Response