I have a (abstract) base class called Product. This class serves as a 'least common denominator'-class for all the other product types. It holds certain variables which all the other products has, e.g ID, name, price, image and so on. I then create a specific product by extending the base class (Product) and then add variables (and functions, which overloads the functions in the baseclass) which is also peculiar for the extended product. To clarify things I'll give you an example: If I wanted a 'Book-product', I extend the Product class and add variables...like author for instance.
To insert, delete and update certain product, I have another baseclass called ProductManager. Again, this class servers as a 'least common denominator'-class. To manipulate 'Book-products', I simply extend the base class and have the functions custom made. Here is an example of how I use the classes:
Code: Select all
require_once("Book.php");
require_once("BookManager.php");
$book = new Book();
$bookManager = new BookManager();
$book->setName("1984");
$book->setAuthor("George Orwell");
$book->setPrice("12.99");
// and so on
$bookManager->insert($book);
$book->setPrice("8.99");
$bookManager->update($book);Thanks