Welcome Guest, Not a member yet? Register   Sign In
Implementing a factory pattern in the Model Layer of CI
#1

[eluser]venugopal[/eluser]
Please correct if this approach is wrong or suggest any other approach to achieve this.

We are designing an ECommerce platform using CI. There are multiple shops and the same product can be made available in multiple shops. But the properties of the product differ from shop to shop.

e.g price of the product A in shop 1 is $5 and in shop 2 its $5.2 etc. But the basic properties like name, description etc are same across all shops.

I am trying to design something like this

abstract class product
{
....function setName();
....function getName();
....function setPrice();
....function getPrice();
}
class Shop1Product extends product
{
....function setPrice()
....{
........ load the price from the DB and return
....}
....function getPrice() { // }
}
class Shop2Product extends product
{
....function setPrice()
....{
........ load the price from the DB and return
....}
....function getPrice() { // }
}
class ProductFactory
{
....function getProduct($productId)
....{
.......//load the context of the current shop which is available by some other means
.......accordingly
...........return newShop1Product();
.......or
...........return newShop2Product();
....}
}


I want these classes to stay in MODEL Layer and the CONTROLLER should get either Shop1Product or Shop2Product from the ProductFactory. Which class should extends CI_Model Class and what should be the code in the Contoller.


Messages In This Thread
Implementing a factory pattern in the Model Layer of CI - by El Forum - 07-14-2010, 01:45 AM
Implementing a factory pattern in the Model Layer of CI - by El Forum - 07-14-2010, 05:03 AM
Implementing a factory pattern in the Model Layer of CI - by El Forum - 07-14-2010, 06:21 AM
Implementing a factory pattern in the Model Layer of CI - by El Forum - 07-14-2010, 06:45 AM
Implementing a factory pattern in the Model Layer of CI - by El Forum - 07-14-2010, 06:45 AM
Implementing a factory pattern in the Model Layer of CI - by El Forum - 07-14-2010, 06:52 AM
Implementing a factory pattern in the Model Layer of CI - by El Forum - 07-16-2010, 12:44 AM
Implementing a factory pattern in the Model Layer of CI - by El Forum - 08-05-2010, 10:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB