- Messages
- 1,420
- Reaction score
- 46
- Points
- 48
As some of you may be aware, I already have a functioning site (see signature) and I am currently looking to rebuild the backend and move to a better structure that is both faster and easier to extend. At the moment it is a mash-up of all sorts of unused code and poor standards. However, I'm looking for some quick input on how best to structure the backend, with a few specific issues.
I'll start by outlining a few of the base classes as I see they may be necessary:
However, once I have these classes set out, there are a number of ways in which the methods and the objects could be structured:
Method 1:
In this method, the Account instance is within the FPD instance. The plan object also has methods within it that can be called:
The fpd and account instances have access to one another, although that may not be important.
However, this method means I may end up with calls such as $fpd->account->username; whilst this is no problem in practice, it might just be a little convoluted.
Method 2:
In this method, the Account instance is separate from the FPD instance, but would then have to be brought in somehow. The plan object also no methods within it and all functions for them are held within the FPD parent:
Method n:
Neither of the above structures, I've got it all wrong and should start again.
Queries:
So essentially I have two main questions:
1. How should the Account and FPD instances be nested; should account be held within the FPD instance or should it be external? Or is it just a matter of preference?
2. Should the Plan class have it's own methods to call, or should the methods be within the FPD class and have the Plan instance as an argument.
Once this is sorted it'll be on to the frontend, which is in even more dire need to some work; it's the consequence of nearly two years of poor structure.
I'll start by outlining a few of the base classes as I see they may be necessary:
PHP:
class FPD // This is the main class that contains shared functions
class Account // Manages account specific methods and data
class Plan // The unit object that is created on a load from database, contains the info for one single plan
// There may also be a Database class, for instantiating connections and handling requests.
Method 1:
In this method, the Account instance is within the FPD instance. The plan object also has methods within it that can be called:
PHP:
$fpd = new FPD;
$fpd->account = new Account;
//load a plan object
$plan = $fpd->load(index); // Returns an instance of Plan class
//Get the length of the plan
$distance = $plan->getDistance(); // This may make more sense to be a static method though
However, this method means I may end up with calls such as $fpd->account->username; whilst this is no problem in practice, it might just be a little convoluted.
Method 2:
In this method, the Account instance is separate from the FPD instance, but would then have to be brought in somehow. The plan object also no methods within it and all functions for them are held within the FPD parent:
PHP:
$fpd = new FPD;
$account = new Account;
//load a plan object
$plan = $fpd->load(index); // Returns an instance of Plan class
//Get the length of the plan
$distance = $fpd->getPlanDistance($plan);
Method n:
Neither of the above structures, I've got it all wrong and should start again.
Queries:
So essentially I have two main questions:
1. How should the Account and FPD instances be nested; should account be held within the FPD instance or should it be external? Or is it just a matter of preference?
2. Should the Plan class have it's own methods to call, or should the methods be within the FPD class and have the Plan instance as an argument.
Once this is sorted it'll be on to the frontend, which is in even more dire need to some work; it's the consequence of nearly two years of poor structure.