Sebarry Posted December 22, 2009 Share Posted December 22, 2009 Hi, I'm new to Object Orientation and I'm trying to write a set of classes for an E-Commerce project. The classes are to represent the interaction between purchaseable products, a shopping basket to hold them in and customers. Here's the code I've got so far. public class Product { private $title = ""; private $description = ""; public function __construct( $title, $description ) { $this->title = $title; $this->description = $description; } ..... } public class ShopProduct extends Product implements Chargeable { private $images; private ProductSize $sizes; .... } public class ProductSize { private $sizeDescription; private $price; private $stockStatus; private $colour; .... } public class ShoppingBasket { private Product $items; private $quantity; ... } public class Customer { private $firstName; private $lastName; ... private ShoppingBasket $basket; ... } Do this look ok? The idea is to have a generic Product class that has the bare minimal details of a product, namely a title and description. A ShopProduct extends this so that image and size information can be stored. The image information is just a string array of filenames. The size information is the actual size, price, colour and stock status i.e. Large, £5.00, Blue and In Stock. The ShoppingBasket should be capable of holding Products i.e. either Products or Shop Products. However, what is actually stored in the basket is not a Product but a ProductSize. Does that make sense? or do I need a separate class of Item? It doesn't really work at the moment anyway because $items in ShoppingBasket is an array of Products or ProductSizes and quantity is a single scalar value. Quantity really needs to be store for each Product or ProductSize that's in the basket. Any help most appreciated. Thanks, Sean Link to comment https://forums.phpfreaks.com/topic/185998-e-commerce-class-hierarchy/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.