Hi has anyone got any advice on how implement a good class structure? for example, would you put your SQL in one class all HTML in another and all arguments in another or would you generally have a class per page?
My current class 'new_page'...I only have one! is getting to around 300 lines. I would like to split out some of the functions but it would great if anyone has any ideas on how to do this?
Many Thanks Ian.
Class structures
Moderator: General Moderators
- icarpenter
- Forum Commoner
- Posts: 84
- Joined: Mon Mar 07, 2005 8:12 am
- Location: Kent, England
- icarpenter
- Forum Commoner
- Posts: 84
- Joined: Mon Mar 07, 2005 8:12 am
- Location: Kent, England
My practise:
1 class - does one GROUP of closely connected functions
1 function - if you have 1 group of functions that share a same goal, then you just divide that into smaller chunks that make the functionality easier to implement is some other parts of the website or any application.
In your ex.:
1 Class: All SQL queries (execution) and maybe ( in my oppinion ) results retrieval for further use.
Functions in it are one Query and results for that query ( off course if you have several functionaly inter-connected queries - put them in one function.
Hope I made it a bit clearer how to use classes.
However - if I'm wrong those who are more expirienced then me are welcome to correct me.
1 class - does one GROUP of closely connected functions
1 function - if you have 1 group of functions that share a same goal, then you just divide that into smaller chunks that make the functionality easier to implement is some other parts of the website or any application.
In your ex.:
1 Class: All SQL queries (execution) and maybe ( in my oppinion ) results retrieval for further use.
Functions in it are one Query and results for that query ( off course if you have several functionaly inter-connected queries - put them in one function.
Hope I made it a bit clearer how to use classes.
However - if I'm wrong those who are more expirienced then me are welcome to correct me.
- icarpenter
- Forum Commoner
- Posts: 84
- Joined: Mon Mar 07, 2005 8:12 am
- Location: Kent, England
it's getting a little clearer...so breaking down the SQL into smaller chunks ie:
Would you then maybe have another class extended to the SQL class to echo the results???
Code: Select all
Class SQL()
{
var $results;
function query_table($x,$y) // amends table
{
$query = "UPDATE table SET field='$x' WHERE value='$y'";
$this->query($query);
}
function query($x)
{
$result = mysql_query($x)
or die ("Couldn't execute query.");
$this->results = mysql_fetch_array($result)
}
}