設計模式 抽象工廠

2021-07-15 04:41:26 字數 3613 閱讀 1182

抽象工廠關注點是:乙個工廠裡面可以建立多種型別的例項

比如 既可以建立 phone 也可以建立pad

抽象工廠包含多少個職責,分別建立不同型別的例項

抽象工廠和簡單工廠的區別在於,工廠可以擴充套件

抽象工廠適合工廠職責是穩定的情況下

平板基類

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace designmode.inte***ce

}

ipad類

using designmode.inte***ce;

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace abstractfactory

online", this.gettype().name);

}public

override

void

photo()

photo", this.gettype().name);}}

}

山寨版 ipad類

using designmode.inte***ce;

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace abstractfactory

online", this.gettype().name);

}public

override

void

photo()

photo", this.gettype().name);}}

}

手機基類

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace designmode.inte***ce

}

iphone 類

using designmode.inte***ce;

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace abstractfactory

public

override

void

call()

call", this.gettype().name);

}public

override

void

text()

text", this.gettype().name);}}

}

山寨版 iphone 類

using designmode.inte***ce;

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace abstractfactory

public

override

void

call()

call", this.gettype().name);

}public

override

void

text()

text", this.gettype().name);}}

}

抽象工廠

using designmode.inte***ce;

using system;

using system.collections.generic;

using system.configuration;

using system.linq;

using system.text;

using system.threading.tasks;

namespace abstractfactory

}

美版工廠

using designmode.inte***ce;

using system;

using system.collections.generic;

using system.configuration;

using system.linq;

using system.text;

using system.threading.tasks;

namespace abstractfactory

public

override basephone createiphone()

}}

國版工廠(山寨版工廠)

using designmode.inte***ce;

using system;

using system.collections.generic;

using system.configuration;

using system.linq;

using system.text;

using system.threading.tasks;

namespace abstractfactory

public

override basephone createiphone()

}}

上端呼叫

using abstractfactory;

using designmode.inte***ce;

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

namespace

console.readkey();}}

}

抽象工廠模式 常用設計模式 抽象工廠模式

提供乙個建立一系列相關或相互依賴物件的介面,而無需指定它們具體的類。在工廠方法模式中,我們的具體建立者每次使用都只能建立乙個同型別的物件,假如我們現在需要的是多個不同型別的物件,工廠方法就滿足不了需求了。這時我們可以把多個工廠方法組合到乙個類,這就是抽象工廠模式,它就是專門用來建立多個產品,也可以說...

抽象工廠模式 設計模式(九) 抽象工廠模式

提供乙個為建立一組相關或相互依賴物件的介面,且無須指定它們的具體類。它屬於建立型模式。在抽象工廠模式中,每個具體工廠都提供了多個用於建立多種不同型別具體物件的方法,這些不同型別的物件都存在乙個共同的屬性,構成乙個族。上篇文章設計模式 八 工廠方法模式說到工廠方法模式中只考慮某一類產品的生產,例如可樂...

設計模式 工廠模式 抽象工廠模式

建立物件時不會對客戶暴露建立邏輯,並且通過使用乙個共同的介面來指向建立的物件。sept1 建立乙個公共介面,將要對外開放的方法在這裡定義。sept2 建立實現介面的類,用即實現對外開放的類的方法 sept3 建立工廠,提供乙個get方法,這個方法提供返回實現類的物件 建立選擇 sept4 使用,建立...