Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP OOP Architectural Issue
    primarykey
    data
    text
    <p>This question may be obvious to some, but I am just beginning to scratch the surface of multi-tier architecture with web applications, particularly with PHP. I have a library containing several objects and it is expanding quickly. I always try to think in terms of re-useability and break my projects down into small, reusable, and loosely coupled components so that I am not only creating the project but I am also creating the parts for future projects. I am trying to design a sort of package management system so that I can stop using the absolute paths within include statements for objects. I would like to have a single file containing includes to every class file within my library. Along with the includes, I want to add a class with a "singleton" pattern that will allow me to grab instances of every object that I have in the library on demand. I plan to create a static getter for each object that returns a reference to a new instance. Basically, something like this...</p> <pre><code>include('classa.php'); include('classb.php'); include('classc.php'); class pacman{ private static $instance_stack; public static function GetPackage($strPackage){ if(!self::$instance_stack){ self::$instance_stack['classa']=new ClassA(); self::$instance_stack['classb']=new ClassB(); self::$instance_stack['classc']=new ClassC(); } if(array_key_exists(strtolower($strPackage),self::$instance_stack)){ return self::$instance_stack[strtolower($strPackage)]; } else{ return false; } } } </code></pre> <p>Then if I want to get class a...</p> <pre><code>include('pacman.php'); $ClassA = pacman::GetPackage('classa'); </code></pre> <p>I realize that this is a very rudimentary implementation. My example just covers the bare minimum. My problem isn't implementing this; rather, it is a question of whether or not hundreds of uninstantiated classes from the includes will have a noticeable effect on performance. If so, does anyone know of a workaround? I can't tell you how hard it is to keep track of the relative paths of hundreds of classes all sorted into directors by content.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload