Design Patterns used in Mandelbrot
Model-View-Controller
Mandelbrot was written with an effort to separate the UI logic from the "domain" logic, which is a loose
interpretation of the MVC pattern. This has benefits in clarity and maintainability of code, and also
allows the program to run in GUI mode or command line mode.
Command
The Task class is an example of the command pattern. It could be used to implement a history feature.
Singleton
Global holds application scope variables and is a singleton. Global is also an example of the Registry pattern from
Martin Fowler's book, Patterns of Enterprise Application Architecture. Yes, this is
global data and global is bad, but there are some objects that legitimately exist at application scope. This
is the place for those objects.
Memento
A Bookmark is a memento. It holds a set of parameters which can be used to reconstitute the "state".
Proxy
Remote threads are wrapped by a proxy which hides their "remoteness" from the client code. In this
case, the proxy handles any RemoteExceptions that occur.
Composite
I wanted to use composite to structure the various types of
generators, but I couldn't quite pull it off. You'd think this would be
a natural fit. But, the interaction between the ui and the main generator thread is very
different from the the interaction between the main generator and its
contained threads, and again very different from remote generators, so the
pattern isn't as clear cut as it is in other situations.
Strategy
Renderer is a class that encapsulates the algorithm for generating the fractal image. If I wanted
to support other types of fractal, I could write new renderers for those fractal types.
Template Method
AbstractGeneratorThread has an abstract method for performing a task: perform(Task task). This method is meant to be implemented
by any subclass of AbstractGeneratorThread. This allows the abstract base class to concentrate on one part of the problem -- in
this case threading -- while leaving the details of how to perform a task up to the subclasses. The variation in how the
task is performed is then isolated from the commonality in how the threading is implemented.