Abstract Factory Pattern
※ 情境 : 如果程式碼需要與多個不同系列的相關產品互動, 但是由於無法提前獲取相關資訊, 或者出於對未來擴展性的考慮, 你不希望程式碼基於產品的具體類進行建構, 在這種情況下, 你可以使用抽象工廠。
Interface
1 | type Shirts interface { |
Office Clothes
1 | type WorkShirts struct{} |
Home Clothes
1 | type VacationShirts struct{} |
Office Factory
1 | type OfficeFactory struct{} |
Home Factory
1 | type HomeFactory struct{} |
Test
1 | package test |