Evolution of an Application: how to manage and improve core engine?
Posted
by
Phil Carter
on Programmers
See other posts from Programmers
or by Phil Carter
Published on 2012-06-26T09:35:44Z
Indexed on
2012/06/26
15:24 UTC
Read the original article
Hit count: 415
design-patterns
|software-evaluation
The web application I work on has been live for a year now, but it's time for it to evolve and one of the ways in which it is evolving is into a multi-brand application - in this case several different companies using the application, different templates/content and some slight business logic changes between them.
The problem I'm facing is implementing a best practice across the site where there are differences in business logic for each brand. These will mostly be very superficial, using a an alternative mailing list provider or capturing some extra data in a form.
I don't want to have if(brand === x) { ... } else { ... } all over the site especially as most of what needs to be changed can be handled with extending the existing class.
I've thought of several methods that could be used to instantiate the correct class, but I'm just not sure which is going to be best especially as some seem to lead to duplication of more code than should be necessary.
Here's what I've considered:
1) Use a Static Loader similar to Zend_Loader which can take the class being requested, and has knowledge of the Brand and can then return the correct object.
$class = App_Loader::getObject('User', $brand);
2) Factory classes. We use these in the application already for Products but we could utilise them here also to provide a transparent interface to the class.
3) Routing the page request to a specific brand controller. This however seems like it would duplicate a lot of code/logic.
Is there a pattern or something else I should be considering to solve this problem?
4) How to manage a growing project that has multiple custom instances in production?
Update This is a PHP application so the decisions on which class to load are made per request. There could be upwards of 100+ different 'brands' running.
© Programmers or respective owner