Welcome Guest, Not a member yet? Register   Sign In
Best way to design OO classes
#3

[eluser]Teks[/eluser]
It is quite a common design pattern for Model-layer classes to have CRUD operations (= create/read/update/delete) that can be performed either on an individual record, or on a set.

In php, you can write methods that check to see whether the parameter that has been passed is either a single value - such as an 'id' - or an array of objects, and then perform the appropriate operation.

Code:
function delete($target){
  if (is_array($target)){
    //check that array contains appropriate data, then
    //do a loop through it, deleting every record included:
    [....]
  }
  else {
    //$target is a single entry, so check that
    // it is an 'id', then delete the appropriate record:
    [...]
  }
}


Messages In This Thread
Best way to design OO classes - by El Forum - 12-02-2008, 10:43 AM
Best way to design OO classes - by El Forum - 12-03-2008, 03:53 AM
Best way to design OO classes - by El Forum - 12-03-2008, 05:09 PM
Best way to design OO classes - by El Forum - 12-08-2008, 07:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB