Observer - emulate multi-threading?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Observer - emulate multi-threading?

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply