Ben Carey
Ben Carey

Reputation: 16968

Procedural or OOP for Website with Multiple Subdomains

Brief Explanation

I am unsure about the structure that I have used for this group of websites. I have tried to share as much code throughout these websites as possible in order to minimise duplicate code and improve efficiency. However, I am not sure whether it is good OOP and would therefore like to hear some other views about it and whether or not I should change the structure.

Consider these websites:

www.domain.com
support.domain.com
clients.domain.com
export.domain.com
etc

I started by creating a class called class.domain.php. This class contains all of the global methods for the Web Application.

Then for each subdomain I created a sub class such as class.www.php, class.support.php etc.

If there are any large sectors of these subdomains then I create further subclasses to reduce the size of the parent class.

So effectively I have ended up with a family tree of classes like so:

Class Relational Tree

Each class contains methods that are relevant to that particular site/section. The methods include things such as:

  1. Gathering dynamic data and returning it to the page
  2. Processing forms and sending emails (contact, support requests etc).
  3. Security Token system
  4. Login System
  5. etc

My Questions

Not only do I want to know whether this structure is good, I also would like to know whether or not I should be using OOP for things such as processing 'contact' forms etc.

It just seems a bit extravagant (and hard to maintain) if I have individual methods for each form. The forms are too unique to be managed by one global method so they either have to be processed using a unique method for each form, or by having a script for each form that has nothing do do with the class (would be easier to maintain).

To summarize:

  1. Is this structure an effective and good OOP structure?
  2. Should I be processing my forms with individual methods within the classes or should I be writing individual scripts for each of the forms?

Thanks in Advance

Upvotes: 0

Views: 100

Answers (1)

Soundz
Soundz

Reputation: 1300

Seems fine to me.

You can make things a bit more abstract maybe by implementing an interface or some abstract functions for the formprocess e.g.

You can write a BaseForm and all childs of BaseForm need to implement "validate()", "process()". That given you can always be certain that your classes implement those methods. So that you can use it in your action like

$form->validate($post_data);
if($form->isValid()){
  $form->process();
} else {
  $form->handleError();
}

since you have the possibility to write OOP, i suggest you to it since its also a lot easier to maintain it.

I still have to fiddle arround with older projects (like osCommerce) at my work and could scream when i see all the code duplications and if a single file contains about 3000-4000 lines of code with if-clauses spanning for a thousand lines you can very hard maintain it. So for your own sake: stick to oop

Upvotes: 1

Related Questions