UML中的五種關系和設計模式中的代碼實現. 又重新聽了一遍UML中的關系.感覺又是收獲很大. UML中的關系有依賴,關聯(聚合,組合),泛化(也叫繼承),實現 現在一個一個的來實現: 一:依賴 依賴關系圖 他的意思就是Use a 用到的意思,兩個類的代碼中不體現 看代碼(C#)  但是在代碼中不體現,怎么反映他們之間的依賴關系呢? 具體的有三種 1:water是公共的類,animal可以調用 2:water是animal的一個方法中的變量 3:water是animal函數的參數返回值 在看看設計模式中依賴的具體舉例
1: //策略模式的現金收費工廠類依賴正常收費子類收費子類
2:
3: //收費抽象類
4: abstract class CashSuper
5: {
6: public abstract double acceptCash(double money);
7:
8: }
9: //正常收費子類
10: class NormalSuper : CashSuper
11: {
12: public override double acceptCash(double money)
13: {
14: return money;
15: }
16: }
17: //現金收費工廠類
18: class CashFactory
19: {
20: public static CashSuper createCashAccept(string type)
21: {
22: CashSuper cs = null;
23: if (type =="正常收費")
24: cs=new NormalSuper() ;
25: return cs;
26: }
27: }
|