freelanceprogrammers.org Forum Index » PHP
Class facotry
Joined: 05 Apr 2005
Posts: 11
Class facotry
Hi All,
I`ve built an application framework on top of PHP Fusebox 3
(http://www.fusebox.org). Though Fusebox is procedural, most of what I do is
actually OO. I use this framework to build client applications quickly and
over time it`s matured to the point that I`m very productive with it.
I host all my clients` applications. They all have their own document roots,
but I use symlinks to have them all point to the same code base. The only
differences between clients are layout files and a per-client config file
that has various application-specific constants.
Now I`m at a point where I want to be able to dynamically load certain
classes based on which application is running. As a simple example, the
menuing system varies dramatically between clients beause they have their
own visual tastes. I use a Factory method to instanciate practically all of
my objects e.g.:
require_once(`Menu.php`);
$menu=Menu::Factory();
The underlying code looks something like this.
class Menu {
//in most cases Factory is inherited
function Factory() {
if(CLIENT=`client1`) {
require_once(`client1Menu.php`);
return new client1Menu;
} elseif (CLIENT=`client2`) {
require_once(`client2Menu.php`);
return new client1Menu;
} else {
return new Menu();
}
}
}
This works reasonably well, but being an architecture junkie I`d like to not
have to define the factory rules in code. Instead, I`d like a pure
algorithmic approach. As an example, have it look in a custom classes
directory for a file that has the same name as the current class plus some
client-specific string that can be expressed as a constant (i.e.
file_exists(CLIENTNAME . `classname.php`)).
Also, I`ve thought about using a monolitic factory for all objects. Just a
function called Factory() and all objects are instanciated from there. Is
that a common practice? Pros & cons?
Thanks!
-Derek
303-543-1186 phone
303-808-6614 cell
425-920-6124 fax
My Latest Blog Entries
<http://feeds.feedburner.com/AskDerekScruggs.gif?bb=o3y6>
[Non-text portions of this message have been removed]
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







