2010-11-09 80 views
0

假設我正在建模這個場景 - 我可以用什麼樣的設計模式來最好地建模?我使用什麼設計模式?

基類是一個CellPhonePlan。 CellPhonePlan有兩個屬性:

  • INT MonthlyPrice字符串類型的
  • 名單,StandardFeatures

凡StandardFeatures可能包括一個值,如 「200分鐘通話時間」。

我也想給標準的CellPhonePlan提供一些插件。如

1)家庭計劃

  • INT價格
  • 類型的字符串列表,功能

2)WeekendPlan

  • INT價格
  • 類型的列表字符串,功能

我希望能夠選擇StandardFeatures,FamilyPlan和WeekendPlan,並且它的價格和功能反映了我所做的選項。我也想知道如何用設計模式來最好地代表這個!

感謝


對不起,我想我沒有解釋得太清楚。我所追求的是基本計劃加上家庭,再加上週末。所以所有的值加起來。

回答

4

需要任何設計圖案......

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" } 
}; 
1

這看起來可能很好地成爲Decorator pattern,如果你真的想使用設計模式。

+0

這是完美的謝謝!我現在試着弄清楚如何將它標記爲答案。 – Lothar 2010-11-09 16:01:19