OO wonders

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • odel

    OO wonders

    hi

    I'm using the model view controller to develop an application

    each class of the controller package (FileController , ArticleControll er)
    has the main controller (Controller) as a member.

    The controller has the DbAccess object as a member

    which means that when I need to call the a method of the DbAccess from a
    controller class, it looks like that :

    $this->oController->oDbAccess->fetchArray(... ) for example.

    Now my question is, is that a problem for the performance of the
    application. Should I declare the Controller and the DbAccess as GLOBAL
    variables or doesn't it matter ? I prefer to avoid using GLOBAL, I think
    it's ugly, but would be happy to use it if it's good for the speed of
    the code.

    Since php is not fully object oriented, I'm sometimes wondering if
    designing it Java or Python style is not a bad idea.

    Any comment appreciated !

    thanks

    .b
  • Jochen Daum

    #2
    Re: OO wonders

    Hi odel!

    On Tue, 21 Oct 2003 13:05:03 +0100, odel <b@twin-pix.com> wrote:
    [color=blue]
    >hi
    >
    >I'm using the model view controller to develop an application
    >
    >each class of the controller package (FileController , ArticleControll er)
    >has the main controller (Controller) as a member.
    >
    >The controller has the DbAccess object as a member
    >
    >which means that when I need to call the a method of the DbAccess from a
    >controller class, it looks like that :
    >
    >$this->oController->oDbAccess->fetchArray(... ) for example.
    >
    >Now my question is, is that a problem for the performance of the
    >application. Should I declare the Controller and the DbAccess as GLOBAL
    >variables or doesn't it matter ? I prefer to avoid using GLOBAL, I think
    >it's ugly, but would be happy to use it if it's good for the speed of
    >the code.
    >[/color]

    You can use a singleton object instead of a global.

    something like:

    class mediator {

    function &project_instan ce(){

    static $instance;

    if (!isset($instan ce)){
    $instance = new project();
    }

    return $instance;
    }
    }

    $x =& mediator::proje ct_instance();

    This will give you always the same object, without using global.

    HTH, Jochen
    --
    Jochen Daum - CANS Ltd.
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

    Comment

    Working...