Jump to: navigation, search

OTExample Observer

Revision as of 05:31, 24 February 2010 by Stephan.cs.tu-berlin.de (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This is a reusable implementation of the omnipresent design pattern "Observer"

Note, that a well designed program in Object Teams will usually not require an explicit Observer infrastructure. See the Stopwatch example for an example, how a plain callin-binding (OTJLD §4) suffices.

This demo should, however, give a quick understanding to some techniques of Object Teams for all who are familiar with the Observer pattern. In fact, after studying this example you will already know most of the relevant Object Teams concept needed for most applications.

Note: the OTDT ships with a slightly simpler version of this pattern.

Elements of the example

protocol/
ObserverPattern
This implements the GoF pattern very straight forwardly.

Open spots are:

  • method Subject.changeOp which should be triggered at relevant base-level events
  • and the abstract method Observer.update() which should realize the Observer's reaction.
flower_example/
Bee
Hummingbird
Flower
Implement some base entities
flower_example/
ObservingOpen
ObservingClose
Two applications of the Observer pattern
binding the above open spots using callin (OTJLD §4) and callout (OTJLD §3) bindings.
flower_example/
Main
A simple main program