1

I may not have my terms right here, so please edit for clarity.

Let's say I have code for running a online shop that has a number of different classes/objects associated with it (Order, Customer, Product etc)

Then, I have particular stores, like a Shoe Store and a Pencil Shop, and each implements different aspects of the Base Store.

In an MVC pattern, how do I design an app so that I don't have write a subclass for each object for each type of store? (This would quickly get unwieldy if I had many stores).

For instance, given these modes:

models/baseOrders.file

models/baseCustomers.file

models/baseProducts.file

models/shoeStoreOrders.file (extends baseOrders)

models/pencilShopCustomers.file (extends baseCustomers)

Then I'd like to be able to instantiate an orders model, using shoeStoreModel.file when it's the shoe store and baseOrders when it's the pencil store...

Hopefully this is a clear question, but maybe I'm thinking about this incorrectly altogether... Guidance please!!! Thanks in advance...

4

1 回答 1

1

您描述它的方式,子类似乎是开放式的。而且由于(通常)您不能动态创建子类,因此一种解决方案是使用type-object (pdf),其实例代表所需的subclasses

于 2012-06-23T02:35:49.880 回答