æ§æã ãã示ãã¦ãå®æããªãã§ããããããã©ã®ããã«å®è¡ãããããè¨è¿°ãã¾ããå®è£ è¨èªã¯Javaã¨ãããã¨ã«ãã¾ãã
âã³ã¼ã©ãã«ã®å®è£ æ¹å¼
ã³ã¼ã©ãã«ï¼è¿°èªãé¢æ°ãã³ãã³ãï¼ã«çµã¿è¾¼ã¿ã®ãã®ã¯åå¨ãã¾ããããã¹ã¦ã¦ã¼ã¶ã¼å®ç¾©ã§ãã次ã®ãããªã¤ã³ã¿ã¼ãã§ã¼ã¹ã®å®è£ ã¯ã©ã¹ã¨ãã¦ã³ã¼ã©ãã«ãå®ç¾©ãã¾ãã
public interface Callable {
public Object call(Object[] args) throws Exception;
}
public interface Function extends Callable {
}
public interface Predicate extends Function {
Boolean call(Object[] args) throws Exception;
}
public interface Command extends Callable {
}
ã³ã¼ã©ãã«ã®ååã¯ãgetName()ãè¨ããã¨ãã¢ããã¼ã·ã§ã³ã§æ¸ãã¨ãã®æ¹æ³ãããã¾ãããããã§ã¯ç´ æ´ã«âè¨å®ãã¡ã¤ã«âã使ããã¨ã«ãã¾ããè¨å®ãã¡ã¤ã«ã®1è¡ã¯ããç¨®å¥ åå ã¯ã©ã¹åãã¨ã§ããã¦ããã¾ããããä¾ãã°ï¼
predicate empty org.example.hoge.Empty
predicate less org.example.hoge.Less
function add org.example.hoge.Add
command doUpdate com.example.foo.DoUpdate
ãã®æ¹å¼ã§ã¯æ¬¡ã®ç¹ã注æããå¿ è¦ãããã¾ãã
- è¨å®ãã¡ã¤ã«ã«ã¯å¼æ°ã»æ»ãå¤ã®æ å ±ããªãã®ã§ãå¼æ°ã®åæ°ã»åã®ãã§ãã¯ã¯ã³ã¼ã©ãã«å®è£ å´ã®è²¬ä»»ã«ãªãã
- ==, <, + ãªã©ã®åºæ¬çæ¼ç®åããªãã®ã§ãã³ã¼ã©ãã«ã¨ãã¦å®è£ ããå¿ è¦ãããã
- ã³ã¼ã©ãã«ãæå±ããåå空éã¯ãã©ãããªã®ã§ãååã®è¡çªã«æ°ãä»ããã
ãããã好ã¾ãããªãç¹å¾´ã§ãããã¾ã¼ãããã§ãããã¨ãã¾ããã¦ã¼ã¶ã¼å®ç¾©ã®ï¼ãã©ã°ã¤ã³ã®ï¼ã³ã¼ã©ãã«ã¯ãå¼æ°ãªãã³ã³ã¹ãã©ã¯ã¿ã§çæããã¦ãè¨å®ããã種å¥ã¨ååã§ä½¿ç¨ããã¾ãã
åé¡ãè¦æ±ãããã°ãã³ã¼ã©ãã«ã«é¢ããæ å ±ãï¼ã¢ããã¼ã·ã§ã³ãå«ãï¼ãªãã¬ã¯ã·ã§ã³ã«ããåå¾ãã¦ãç²¾å¯ãªå¼æ°ã»æ»ãå¤æ å ±ã«åºã¥ããåãã§ãã¯ããã¬ã¼ã ã¯ã¼ã¯å´ã§è¡ããã¨ãèæ ®ãã¾ãï¼ã£ã¦ãã¨ã¯ãåé¡ï¼è¦æ±ããªããã°ãããªãã£ã¦ãã¨ï¼ã
âãã¬ã¼ã ã¯ã¼ã¯ã®ä»äº
æ§æ解æã«ãã£ã¦ä½ãããã«ã¼ã«ã®ãã¼ã¿æ§é ããã©ããªããã次ã®ãã§ãã¯ããã¾ãã
- æ¡ä»¶å¼ã®ãããã¬ãã«ã«åºç¾ããã³ã¼ã©ãã«ãâåå¨ããè¿°èªâã§ãããã©ããã
- ã¢ã¯ã·ã§ã³ã®ãããã¬ãã«ã«åºç¾ããã³ã¼ã©ãã«ãâåå¨ããâãã©ããã
- å¼æ°å ã«åºç¾ããã³ã¼ã©ãã«ãâåå¨ããé¢æ°âã§ãããã©ããã
以åã¨èããå¤ãã£ãã®ã¯ããã¢ã¯ã·ã§ã³ã®ãããã¬ãã«ã¯ã³ãã³ããã®å¶éãã¯ããã¦ãã©ããªã³ã¼ã©ãã«ã§ããããã¨ããã¨ããã§ãã
次ã«ãå¼ã¨ã¢ã¯ã·ã§ã³ã®è©ä¾¡ã§ããï¼
- å¤æ°ã¯åºç¾ãããçæãï¼ãã¼ã¿æ§é ããã©ã£ãã¨ãã«ä½ã£ã¦ããã¦ããããï¼ãåæå¤ã¯nullã¨ããã
- ãªãã©ã«ã¯ããèªèº«ã«è©ä¾¡ãããã
- ã³ã¼ã©ãã«ã®å¼ã³åºãã¯ãäºåã«å ¨ã¦ã®å¼æ°ãè©ä¾¡ãã¦å¼æ°ãªã¹ãï¼é åï¼ãä½ããçæããã³ã¼ã©ãã«å®ä½ã®callãå¼ã³åºãã
- ä»£å ¥æã¯ãå³è¾ºãè©ä¾¡ããçµæãå¤æ°ã¨ãã¦ã»ãããããä»£å ¥æ以å¤ã®âæã®å¤âã¯æ¨ã¦ãã
å¤æ°ã¨ã³ã¼ã©ãã«ã¯ãååããã¼ã¨ãã¦ãããã§ç®¡çããã§ãããããå¤æ°ã¨ã³ã¼ã©ãã«ã§å¥ãªãããã使ããã¨ã«ãã¾ããã¤ã¾ããåãååã®å¤æ°ã¨ã³ã¼ã©ãã«ã許ãã¾ãï¼ãã®äºãå¾ã§ä½¿ããããããªãï¼ã
âãããã
以ä¸ã®ãããªè©ä¾¡ã«ä¾¿å©ãªããã«ãã¼ãºçµæãã¼ã¿æ§é ãèãããã¨ã«ãã¾ããããã¨ãã«ã¼ã«ã®æåã»å¤±æã«å¿ããå¦çã«ã¤ãã¦ãèããå¿ è¦ãããã¾ãã