抽象工厂模型 了解设计模型的人都该清楚啊 代码自己打一下 比较清楚啊
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 抽象工厂
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入你要购买的水果:");
string FruitName = Console.ReadLine();
IFruit Fruit = null;
FruitFactory MyFactory = new FruitFactory();
switch (FruitName) {
case "苹果":
Fruit = MyFactory.MakeApple();
break;
case "橘子":
Fruit = MyFactory.MakeOrange();
break;
default:
Console.WriteLine("别瞎写 就两种水果!");
break;
}
Console.ReadLine();
}
}
interface IFruit {
}
public class Apple : IFruit {
public Apple(){
Console.WriteLine("An Apple is Got!");
}
}
public class Orange : IFruit {
public Orange() {
Console.WriteLine("An Orange is Got!");
}
}
public class FruitFactory {
public Apple MakeApple() {
return new Apple();
}
public Orange MakeOrange() {
return new Orange();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 抽象工厂
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入你要购买的水果:");
string FruitName = Console.ReadLine();
IFruit Fruit = null;
FruitFactory MyFactory = new FruitFactory();
switch (FruitName) {
case "苹果":
Fruit = MyFactory.MakeApple();
break;
case "橘子":
Fruit = MyFactory.MakeOrange();
break;
default:
Console.WriteLine("别瞎写 就两种水果!");
break;
}
Console.ReadLine();
}
}
interface IFruit {
}
public class Apple : IFruit {
public Apple(){
Console.WriteLine("An Apple is Got!");
}
}
public class Orange : IFruit {
public Orange() {
Console.WriteLine("An Orange is Got!");
}
}
public class FruitFactory {
public Apple MakeApple() {
return new Apple();
}
public Orange MakeOrange() {
return new Orange();
}
}
}