// outline of using observer pattern for the goblins program. superclass player class human : player (also apply singleton pattern) class goblin1 : player class goblin2 : player class treasure : player --------- independent hierarchy: goblins are observers, human is observee or (subject) // Abstract interfaces interface observee // abstract subject { void attach(observer A); void detach(observer A); void notify(); } interface observer { void update(observee B); } class human : player, observee class goblin1 : player, observer class goblin2 : player, observer class treasure : player, observer class human: player, observee { ArrayList obsvs = new arraylist; // list of observers public void attach(observer A) { obsvs.Add(A); } public void detach(observer A) { obsvs.Remove(A); } public void notify() { foreach (observer B in obsvs) { B.update(this); } } public void setdirection(int newdx, int newdy) { dx = newdx; dy = newdy; notify(); } } class goblin1 : player, observer { public void update(observee B) { human prof = (human)B; // change movement vector to try to catch B accordingly //B.dx, B.dy - not available before typecast. } }