Page 1 of 1

Observer - emulate multi-threading?

Posted: Wed Sep 20, 2006 5:36 am
by Jenk
Not that I can see a 'real' use for multi-threaded applications on webpages (note pages, not sites..)

But having looked into the use of the Observer pattern recently, is this just a pseudo multi-threading pattern?

Example;

Code: Select all

$observer = new Observer;

$classA = new ClassA($observer);

$classB = new ClassB($observer);

$classB->initAndWaitForAtoFinishDoingSomething();

$classA->doSomething();

// $classB now kicks off..
I realise that it is only a 'push' implementation of what multi-threading can achieve (i.e. you can't have a

Code: Select all

while ($observer->hasAFinished() != true) { sleep(100); }
and let it wait for A to finish.)

But is this why the Observer pattern, particularly in PHP was brought about?

[/waffle]

Posted: Wed Sep 20, 2006 6:03 am
by feyd
Observers are dependancy links. They allow classes to be loosely coupled and fairly agnostic to each other's internals as they go through a common interface.