首页 > 代码库 > 审判,必须死,关于工厂模式的小小理解
审判,必须死,关于工厂模式的小小理解
不幸,你被抓住了。
明朝皇帝不会留情的。他冷笑着说:“你必须死!!!”
“交给东厂,审审,决定你的死法”
这个世道啊,连死法,都和你有多少钱相关。
“身上钱少于100块,吃屎到死;多于100,少于200,被袋鼠干,干死;多余200块嘛,天天看郭敬明,郁闷至死。”
于是一段程序开始了:
using UnityEngine; using System.Collections; public class DummyFact : MonoBehaviour { //king want you to die //you are a criminal //many ways to die //depends on your money //money<100 ------>eat shit to die //100<=money <200 ------>fucked by kangaroo to die //mony>=200 ------>read novels by GuoJingMing to die // Use this for initialization void Start () { Criminal you = new Criminal (); you.ToDie (); you.Money = 99; Debug.Log ("your money ="+you.Money); you = SentenceFactory.Sentence (you); you.ToDie (); } // Update is called once per frame void Update () { } } public class Criminal{ private int _money; public int Money { get; set; } public virtual void ToDie(){ Debug.Log ("You should die"); } } public class PoorCriminal:Criminal{ public override void ToDie(){ Debug.Log ("eat shit to die"); } } public class MiddleCriminal:Criminal{ public override void ToDie(){ Debug.Log ("fucked by kangaroo to die"); } } public class RichCriminal:Criminal{ public override void ToDie(){ Debug.Log ("read novels by GuoJingMing to die"); } } public class SentenceFactory{ public static Criminal Sentence(Criminal you){ Criminal youSentenced = null; int money = you.Money; if(money<100){ youSentenced = new PoorCriminal(); } else if(money>=100&&money<200){ youSentenced = new MiddleCriminal(); } else{ youSentenced = new RichCriminal(); } return youSentenced; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。