Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Troubles with layers in Object Oriented design

    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:

    PHP Code:

    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

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    ...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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •