public void test() { //依赖倒置 创建型设计模式 不同场景 //1.简单抽象 利用一个工厂类,具体创建 //2.工厂方法 利用抽象工厂类,抽象创建方法,创建单一实例 //3.抽象工厂 利用抽象工厂类,多个抽象方法,创建一组实例 Orchard wuhanOrchard = new Wuhan_Orchard(); Strawberry strawberry = wuhanOrchard.CreateApple(); WaterMelon waterMelon = wuhanOrchard.CreateWatermelon(); strawberry.plant(); waterMelon.plant(); }
void RunQ5() { Person ninging = new Person("Ningning"); Person wuwu = new Person("Wuwu"); Person zz = new Person("ZZ"); WaterMelon waterMelon = new WaterMelon("sweetWaterMelon", 5.0f); FruitShop fruitShop = new FruitShop(waterMelon, 2); Hat niceHat = new Hat("niceHat", 120.0f); ClothingShop clothingShop = new ClothingShop(niceHat, 1); ninging.BuyItem(fruitShop, 10.0f, waterMelon); ninging.BuyItem(clothingShop, 200.0f, niceHat); ninging.Gifting(ninging.ownedItems[0], wuwu); ninging.Gifting(ninging.ownedItems[0], zz); wuwu.EatFood((BBBB.Food)wuwu.ownedItems[0]); zz.PutOn((BBBB.Clothing)zz.ownedItems[0]); }