...

View Full Version : Troubles with layers in Object Oriented design



Michiel
01-10-2004, 12:19 PM
Hi,

I've got a question concerning classes in php. I'm working on a multi-layered script and I'm having troubles with the general design. The script consists of 3 different layers: a common layer with the database functions, a business layer that does the actual operations and a gui layer. Now I'm looking for a way to connect these layers together in a flexible way. I want to be able to add new layers (with modules) without having to change the entire script.

So far I set up the following design:




class control {

function control() {
$this->common = new common;
$this->business = new business;
$this->gui = new gui;
}

}

class common {
function foo() {
}
}

class business {
function foo() {
}
}

class gui {
function foo() {
}
}


$object = new control;
$object->business->foo();



This design allows me to access all the functions in the different layers via $object->layername->functioname(). However the problem that I still have, is that I cannot call to functions between layers. Eg. from the business layer, I can't access a function from the common layer.

Does anyone know how I can solve this problem or suggest other/ better methods for the general design? Any tips, advice and reading is very much appriciated!

Thanx in advance, Michiel

firepages
01-10-2004, 01:47 PM
...is that I cannot call to functions between layers. Eg. from the business layer, I can't access a function from the common layer.


...and if you want to use layers `correctly` (there is NO correctly ,but anyway) then technically thats good , eg each layer should only be able to access the one above it.

e.g. you should not be able to access the common layer from the GUI , at least not without some form of multiple inheritance which you wont be getting with PHP for a while.

In reality you may have to break/bend the rules a little (PHP is NOT JAVA or smalltalk etc), you could for instance in your controller do some wrappers for communicating between the major layers (preferably in an extended controller class)

I can't say that I know enough about design patterns to go further , what I do know about classic design patterns is that they are usually an goal but rarely reached especially in PHP.

hopefully someone here can spread more light , but also if you have not already take a look at phppatterns (http://www.phppatterns.com)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum