Wednesday, February 28, 2007

OOP and Me - The $Real->Deal()

So my spat with a purely OOP site design is coming along quite nicely. I've been trying to break out some research on design patterns, but still have yet to truly understand what the hell they're trying to do, other than make it easier for developers later on. I don't think I need this for my site (it'll be just me developing, but if it does take off and I need developers, I'd like to have a pattern in place already). I like the factory idea, and it makes sense. The one I'm interested in, however, is the Registry. I sort of understand it, but I'm not exactly sure the true purpose and how to really implement it for it to make sense to me. I haven't implemented either of these into my design so far, but one day I will. For now, though, I'm sticking to my guns and going with what I know, which is just normal tight coupling (I know, bad bad bad!), but it works for me currently. I wish I could use PHP5, but my host has only 4.3, so I'm limited to a lot of old-world OOP. I had a few interfaces created, only to realize that they didn't work, and I didn't like the idea of using class extenders because I wanted to have the abstract parent to define the functions, not actually implement them.

Back onto my original thought process, I have implemented what I consider to be at least a partial "front controller". The class itself is called Page, and just handles the creation of the page, including the template (the templating itself is handled by a template class, soon to be abstracted by an interface [hopefully], including parsing through it), adding controls (dynamic stuff that the template won't be aware of, thus lightening the load somewhat of the template engine), dynamically loading necessary classes, and other maybe like 2 other things. I've got a few design questions that I've got to look into, including the page configuration being dynamic (not sure if I want to have a single sessioned config and be able to change it when I need to, or if I should load the config on each page to allow for different tasks to use different configs).

What it looks like so far, however is: (not all the code, only config portion)


function LoadConfig($config_file)
{
$this->my_config = $config_file;
$contents = file_get_contents($config_file);
preg_match_all("/config\['([a-zA-Z_]*?)'\]\['([a-zA-Z_]*?)'\] = \"(.*?)\";/", $contents, $cfg_values);
for($i=0; $i $this->my_config_values[$cfg_values[1][$i]][$cfg_values[2][$i]] = $cfg_values[3][$i];
}

As you can see my dilemma, is I'm not sure if I want to pass it the config file itself, or just pass it a sessioned config (Singleton!! I understand that much at least). The way it is now has a heavier overhead because of the processing time of loading the config on every single page, but has a more modularized feel that each page in itself can be encapsulated alone.

Once I get some time to work on this from home, I'll be doing some testing of execution times to see if there's a substantial load time optimization that I'll be in for, or if I can let this one slip by as a "necessary evil", so to speak.

Until next time, $this->post->end();

No comments: