jbd
jbd

Reputation: 415

design pattern to handle base/super classes with optional subclasses

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...

Upvotes: 1

Views: 84

Answers (1)

Jordão
Jordão

Reputation: 56477

The way you're describing it, the subclasses seem to be open-ended. And since (usually) you can't create subclasses dynamically, one solution is to use a type-object (pdf), whose instances represent the desired subclasses.

Upvotes: 1

Related Questions