Lothar
Lothar

Reputation: 1

What design pattern do I use for this?

Say I am modelling this scenario - what design pattern could I use to best model this?

The base class is a CellPhonePlan. CellPhonePlan has two properties:

Where StandardFeatures might include a value such as "200 minutes call time".

I also want to provide some addons to the standard CellPhonePlan. Such as

1) Family Plan

2) WeekendPlan

I want to be able to choose the StandardFeatures, FamilyPlan and WeekendPlan and have its price and features reflective of the options I have made. I also would like to know how to best represent this using a design pattern!

Thanks


Sorry I guess I didn't explain that too clearly. What I am after is having the base plan plus the family, plus the weekend. So all the values add up.

Upvotes: 0

Views: 152

Answers (2)

tbischel
tbischel

Reputation: 6477

This looks like it could fit well into the Decorator pattern, if you really want to use a design pattern.

Upvotes: 1

Domenic
Domenic

Reputation: 112807

No design pattern needed...

class CellPhonePlan
{
    int MonthlyPrice { get; set; }
    List<string> Features { get; set; }
}

var standardPlan = new CellPhonePlan
{
    MonthlyPrice = 10,
    Features = new List<string>() { "200 minutes call time", "texting" }
};

var familyPlan = new CellPhonePlan
{
  MonthlyPrice = 20,
  Features = new List<string>() { "500 minutes call time", "texting", "shared between a family" }
};

var weekendPlan = new CellPhonePlan
{
  MonthlyPrice = 5,
  Features = new List<string>() { "200 minutes call time", "but you can only talk on weekends" }
};

Upvotes: 4

Related Questions