Implementing Model-View-Controller Architecture with Observer Pattern
![]()
Incomplete initial specification:
Background
The Model-View-Controller (MVC) architecture [link] is almost ubiquitous to the point of being a gui/web programming paradigm. It is such a natural decoupling approach that it is implicit in most non-trivial programs, whatever the language. However, making it more explicit through the Observer (Publish-Subscribe) Pattern frees up the ‘pluggability’ power of decoupling.
Overview
The mvc decoupling of the pixel data from its visual display allows a richer choice of display techniques as well as liberating the coding of the model. 3 classes will form the basis of this cooperation for pixel based programs:
PixelPublisher (abstract base class)
PixelSubscriber (interface)
PixelSpace (encapsulated state)
Scenario
A concrete PixelPublisher such as a Game of Life [link] or Mandelbrot set [link] model would notify its subscribers with a PixelSpace update to display in whatever manner:
PixelSubscriber.notify(PixelSpace) <--- PixelPublisher
.
.
PixelSubscriber.notify(PixelSpace) <---
Non-goals
Not intended to be single purpose i.e. not a Game of Life only solution
Filed under: Java, game framework, pixel, specification