Observer
Intent
Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
Class diagram of the original GoF pattern

Improvement in MixJuice
Solved Problem(s)
- Introduction problem
- It is impossible to introduce Observer pattern into the existing program without modifying the source code. (This problem is not mentioned in the GoF book.)
Used programming technique(s)
Class extension for Subject.
Consequences
- (+) Observer pattern can be introduced into existing classes.
- (-) Addition of both a new kind of side effect operation and a new kind of observer requires a complementary module. Note that the absence of complementary module is not checked by the MixJuice linker, in this case.
Structure and pseudo code

module original {
define class Subject {
define void sideEffectOperation() {...}
}
}
module extension extends original {
define abstract class Observer {
define abstract void update();
}
class Subject {
define void attach(Observer o) {...}
define void detach(Observer o) {...}
define void changed() {...}
void sideEffectOperation() {
original();
changed();
}
}
}
Akira TANAKA <akr@m17n.org>, Yuuji ICHISUGI <y-ichisugi@aist.go.jp>Top