using UnityEngine;
using System.Collections;
namespace Console
{
public abstract class Computer//定义抽象类
{
public abstract void print();
}
public class Banana : Computer //继承抽象类
{
public override void print() //修改抽象类里的方法
{
Debug.Log("香蕉");
}
}
public class Apple:Computer
{
public override void print()
{
Debug.Log("苹果");
}
}
public class Make //用于判断需求是什么来生成产品
{
public static Computer Create(string type)
{
Computer com = null;
if(type == "香蕉")
{
com = new Banana();
}
if(type == "苹果")
{
com = new Apple();
}
return com;
}
}
class Program //提出需求
{
static void Main(string[] args)
{
Computer com = Make.Create("香蕉");
com.print();
}
}
}