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.

And here is an implementation class.

And another implementation class.

When we test them out like this:

We […]

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:

This does indeed work. But let’s say you just want a Pet and you don’t really care what kind it is as […]

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