策略模式的扩展——策略枚举
生活随笔
收集整理的這篇文章主要介紹了
策略模式的扩展——策略枚举
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
?
?
?
策略枚舉就是這樣一個(gè)枚舉:
- 它是一個(gè)枚舉。
- 它是一個(gè)濃縮了的策略模式的枚舉。
public enum Calculator { //加法運(yùn)算 ADD("+"){ public int exec(int a,int b){ return a + b; } }, //減法運(yùn)算 SUB("-"){ public int exec(int a,int b){ return a - b; } }; String value = ""; //定義成員值類型 private Calculator(String _value){ this.value = _value; } //獲得枚舉成員的值 public String getValue(){ return this.value; } //聲明一個(gè)抽象函數(shù) public abstract int exec(int a,int b); }
作者:wyunteng 發(fā)表于2011-6-28 12:48:00 原文鏈接 閱讀:3 評(píng)論:0 查看評(píng)論轉(zhuǎn)載于:https://www.cnblogs.com/wyinan/archive/2011/05/12/2110427.html
總結(jié)
以上是生活随笔為你收集整理的策略模式的扩展——策略枚举的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: squid 的配置详解 (转)--Ser
- 下一篇: WordPress自动升级插件时需要填写