E-Commerce Class Hierarchy
Posted: Tue Dec 22, 2009 3:11 am
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.
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
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.
Code: Select all
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