ãã¶ã€ã³ãã¿ãŒã³ãšã¯
ðãªããžã§ã¯ãæåèšèšã«ãããŠçŸããðãã¿ãŒã³ããŸãšãããã®.
GoF ãã¶ã€ã³ãã¿ãŒã³
誀解ãããã¡ã ã, GoFãã¶ã€ã³ãã¿ãŒã³ãšã¯ãã¶ã€ã³ãã¿ãŒã³ã®ãªãã®äžéš.
ãã ããã¶ã€ã³ãã¿ãŒã³ããšããåèªèªäœãGoFã§ã¡ãžã£ãŒã«ãªã£ãã, ã¿ããªãã¶ã€ã³ãã¿ãŒã³ãšãããšGoFãæãæµ®ãã¹ãã®ã§, æ矩ã§ã¯åããšããã°åããã®.
çæã«é¢ãããã¶ã€ã³ãã¿ãŒã³
Factoryã®åå.
çæãšå®è£ ãåé¢ããããšã§, ããã°ã©ã ã¯ã·ã³ãã«ã«ãªã.
- çæãã©ã¡ãŒã¿ã®æå®æ¹æ³ãã·ã³ãã«ã«
- çæåŸã®ç®¡çãã·ã³ãã«ã«
- çæãããªããžã§ã¯ãã®æå®æ¹æ³ãã·ã³ãã«ã«
ç¹å®ã®ã±ãŒã¹ã§ç¹å®ã®ãªããžã§ã¯ããçæããã®ã¯æç¶ãæèç.
2 ã€ããããŠèããããšã§èšèšã«éäž.
- åäœæ¹æ³
- çæ,管çæ¹æ³
ðšFactory Method
ãªããžã§ã¯ãã®çæãè¡ãæã®ã€ã³ã¿ãã§ãŒã¹ãèŠå®ããŠ, ã€ã³ã¹ã¿ã³ã¹åããã¯ã©ã¹ã決å®ããã®ã¯ãµãã¯ã©ã¹ã«ä»»ãã. factoryMethod ã®äžã§ãªããžã§ã¯ãã®çæãããããšã§, çæãçæãªããžã§ã¯ã (ã¡ãœãã) å ã«ã«ãã»ã«å.
- typeã®ãããªåŒæ°ãæž¡ã/æ§æãã¡ã€ã«ããèšå®ãèªã¿èŸŒã.
- ifæãswitchæã§åå²ãããŠãªããžã§ã¯ããè¿ã.
- é¢æ°åèšèªãªãã°é¢æ°ãè¿ã.
- get-xx-fn: æäœã®å®è£ éšå. ããã§åå².
- get-xx: æœè±¡åãããæäœã®IF.
Factory Methodã§ããã¿ãé¢æ°å
ãããã€ããŠããfactory methodãã.
- create-foo
- make-foo
- generate-foo
- foo-generator
- foo-factory
C èšèªã§ã®å¿çš
C èšèªã§ Abstruct Data Type ãªèšèšãã€ãããšãã®åžžå¥æ段.
int createInstance (void) {
return calloc (4);
}
int destroyInstance (int ptr) {
free (ptr);
return NULL;
}
int main (void) {
int *instance = createInstance ();
instance = destoryInstance (instance);
return 0;
}
ã°ã«ãŒãåããããªããžã§ã¯ãã«ã€ããŠ,
- çæçšãªããžã§ã¯ã (Creator)
- æ¯ãèãçšãªããžã§ã¯ã (Product)
ã®ãã¢ãäœæãããšã.
Refs
- Factory Method ãã¿ãŒã³ - Wikipedia
- ç¶æ ããã¯ãããã¿ã€ããã¿ãŒã³ã§, ç¶æ ãªãã¯ãã¡ã¯ããªã¡ãœããã§å®è£ (Java) | Futurismo
- https://gist.github.com/db8a24ed41d6806f4187
ðšAbstract Factory
é¢é£ãããªããžã§ã¯ã矀ããã®å ·è±¡ã¯ã©ã¹ãæ確ã«ããã«çæããããã® ã€ã³ã¿ãã§ãŒã¹ãæäŸãã.
é¢é£ããã€ã³ã¹ã¿ã³ã¹çŸ€ãçæããããã® API ãéçŽããããšã«ãã£ãŠ, è€æ°ã®ã¢ãžã¥ãŒã«çŸ€ã®åå©çšãå¹çåããããšãç®çãšãã.
å®è£ ã¯æèããã«, ã€ã³ã¿ãã§ãŒã¹ (API) ã®ã¿ã§, æœè±¡çãªéšåãã€ããããã.
Factory Method èªäœã®ã«ãã»ã«å. Factory Methodã®é²åç. ãã«ã Factory Method. Factory Methods.
èŠç¹ãããããš Factory Method ã® Builder Pattern ãšãèšãã.
ðšBuilder Pattern
ãªããžã§ã¯ãã®çææé ãè€éãªå Žåã«ãã®çæéçšãã«ãã»ã«åãã.
- é¢æ°åãbuild-xxxã¿ãããªãã€.
- ãã¡ã€ã³é§åèšèšã§ãããšããã®ãšã³ãã£ãã£ãªããžã§ã¯ããçæãã Factory.
- æœè±¡ããŒã¿åãšãã¡ã€ã³é§åèšèšã®é¢ä¿ã«ã€ã㊠| Futurismo
- Builder ãã¿ãŒã³ - Wikipedia
- ãšã¬ã¬ã³ã㪠Effective Java ã® Builder Pattern ãå®è£ ããŠã¿ã | Futurismo
ðšPrototype Pattern
çæãããªããžã§ã¯ãã®ååãã³ããŒããŠæ°ãããªããžã§ã¯ããçæãã.
- Prototype ãã¿ãŒã³ - Wikipedia
- ç¶æ ããã¯ãããã¿ã€ããã¿ãŒã³ã§, ç¶æ ãªãã¯ãã¡ã¯ããªã¡ãœããã§å®è£ (Java) | Futurismo
Abstract Factory ãšäŒŒãŠãã.
- new ã§ãªããžã§ã¯ããçæããã° Abstract Factory.
- clone ãã€ããå Žåã® Prototype.
è€è£œãäœæããããã®ã¡ãœãããçšæãã. ãšããããã£ãŠåçŽãªãã®.
ãããã¿ã€ã ãè€è£œãæ åœã, ãã以å€ã®çæã«ãããæäœãã¯ã©ã€ã¢ã³ãã æ ã£ãŠãã.
Map ã«ãã³ãã¬ãŒããç»é²ããŠãããŠ, å©çšãããšãã«è€è£œãã. ãã€ããªããŒã¿ããããã«ãããŠãããŠ, ããŒãšãªãååãã€ããŠç®¡çãã, ãªã©.
Java ã«ã¯, Clonable ã€ã³ã¿ãã§ãŒã¹ããã.
ã¯ã©ã¹ã®æ°ãããªãæžããããšãã§ãã.
Abstract Factory ãã¿ãŒã³ã§ãªãããããã«, ã¯ã©ã€ã¢ã³ãã»ã¢ããªã±ãŒã·ã§ã³ã«ãããŠãªããžã§ã¯ãã®çæè ããµãã¯ã©ã¹ã«ããããšãåé¿ãã.
æšæºçãªæ¹æ³ (äŸãã°ânewâ) ã§æ°ãããªããžã§ã¯ããäœãããšã«ããåºæã®ã³ã¹ããæäžã®ã¢ããªã±ãŒã·ã§ã³ã«ãšã£ãŠé«ãããæã«ãããåé¿ãã.
ðšSingleton Pattern
ã·ã¹ãã å ã§çæå¯èœãªã€ã³ã¹ã¿ã³ã¹æ°ãã²ãšã€ã ãã«å¶éãã.
- Singleton ãã¿ãŒã³ - Wikipedia
- Java ã®ãŠãŒãã£ãªãã£ã¯ã©ã¹ã§ã·ã³ã°ã«ãã³ãã¿ãŒã³ãããã | Futurismo
äžè¬çãªã·ã³ã°ã«ãã³ãã¿ãŒã³ã®å®è£ æ¹æ³ã¯ä»¥äž.
- static method
- private 㪠å®æ°ã« ãªããžã§ã¯ããä¿å
- ãªããžã§ã¯ã㯠getInstance () ã¡ãœããã§ååŸ
å Factory ã®éã
ãã¶ã€ã³ã¯ãã°ãã°,
- æ¯èŒçã«è€éã§ãªã,
- ã«ã¹ã¿ãã€ãºãããã,
- ãµãã¯ã©ã¹ãæ¥éã«å¢ãã
ãã¡ã¯ããªã¡ãœãããçšãããšããããåºçº
äžå±€ã®æè»æ§ãå¿ èŠãšãªãç®æãçºèŠãããã«äŒŽã,ããæè»ã ãè€éAbstract Factory, Prototype, Builder ãžãšçºéããŠãã.
- Prototype ãã¿ãŒã³ - Wikipedia ããåŒçš:
Factory Method
ãã¡ã¯ããªã®ã¯ã©ã€ã¢ã³ããšãªããªããžã§ã¯ãã, ãã¡ã¯ããªãªããžã§ã¯ãã«ã€ã³ã¹ã¿ã³ã¹ã®çæãå§è²ãã.
- 芪ã¯ã©ã¹ã§ãã Creator ã¯ã©ã¹ãåã¯ã©ã¹ã§ãã ConcreteCreator ã¯ã©ã¹ã«ãªããžã§ã¯ãã®çæãå§ãã.
- Creator ã¯ã©ã¹ãš ConcreteCreator ã¯ã©ã¹ãšã®é¢é£ã§ãã.
- ç¶æ¿
- [ãªããžã§ã¯ãçæ] ã®æœè±¡åã«ãã€ã³ãã眮ãããã¿ãŒã³
Abstract Factory
芪ã¯ã©ã¹ã§ãããã¡ã¯ããªã, å®éã®ãªããžã§ã¯ãã®çæããµãã¯ã©ã¹ã«å§è²ãã.
- Client ã®ã€ã³ã¹ã¿ã³ã¹ã ConcreteFactory ã®ã€ã³ã¹ã¿ã³ã¹ã«ãªããžã§ã¯ãã®çæãå§ãã
- ãªããžã§ã¯ãå士ã®é¢é£
- å§è²
- [é¢é£ãããªããžã§ã¯ã矀ããŸãšããŠçæããããã®æé ] ã®æœè±¡å
References
- Abstract Factory ãã¿ãŒã³ - WTOPIA v1.0 documentation
- Abstract Factory ãã¿ãŒã³ ãš Builder ãã¿ãŒã³ã®éã
- ãªããžã§ã¯ãæè: Factory (ãã¡ã¯ããª) ãã¿ãŒã³
æ§é ã«é¢ãããã¿ãŒã³
ðAdapter Pattern
ã€ã³ã¿ãã§ãŒã¹ãå€æããããšã«ããã€ã³ã¿ãã§ãŒã¹ã«äºææ§ããªãã¯ã©ã¹å士ãæ¥ç¶ãã.
åãªãã©ãããŒã¯ã©ã¹ãšãèšãã. ã©ãããŒæ¹æ³ã¯2ã€ãã.
- ç¶æ¿ã§ã©ãããŒãã -> Template Method Pattern
- å§è²ã§ã©ãããŒãã -> Decorator Pattern
- ðã©ãããŒ(Wrapper Pattern)
- Adapter ãã¿ãŒã³ - Wikipedia
- Adapter, Facade, Proxy ãã¿ãŒã³ã®éãã®ã¡ã¢ | Futurismo
- Java 㧠Producer-Consumer Pattern ãå®è£ ããŠã¿ã | Futurismo
æ¥æ¬ã®ã³ã³ã»ã³ããå€åœã®é»æºã«å·®ã蟌ãæã®ã¢ããã¿ãŒ. Type-Cã±ãŒãã«ãUSBã±ãŒãã«ã®å£ã«å·®ã蟌ã¿ãããšãã®ã¢ããã¿ãŒ.
ðšBridge Pattern
ã¯ã©ã€ã¢ã³ããã¢ã¯ã»ã¹ããã¯ã©ã¹ (ã€ã³ã¿ãã§ãŒã¹) ãšå®è£ ã¯ã©ã¹ãåé¢ããŠ, ãããããç¬ç«ã«å€æŽã§ããããã«ãã.
ãªããžã§ã¯ãæåã®ãããã®æ¬ã«ãšãŠã詳ããæžããŠãã. ããã, ãªããžã§ã¯ãæåã®æ¬è³ª! ã¿ãããª. ã€ã³ã¿ãã§ãŒã¹ãçšããŠèšèš ãã.
æ©èœè¿œå ãšæ©èœå®è£ ã®çµã¿åããççºãææ¢ããããšãã§ãã.
ðšComposite Pattern
éšå-å šäœéå±€ãè¡šçŸããããã«, ã¯ã©ã¹ã®æšæ§é ã«çµã¿ç«ãŠã.
åäžã®ã¯ã©ã¹ãã掟çãããµãã¯ã©ã¹ãæšæ§é ã®ããŒããšã, ã¯ã©ã€ã¢ã³ãã¯æšæ§é ã®ä»»æã®éšåãåäžã®ã€ã³ã¿ãã§ãŒã¹ã§æ±ãã.
- Composite ãã¿ãŒã³ - Wikipedia
- ã³ã³ããžããã»ãã¿ãŒã³ (Composite Pattern) ãš TkComposite ã«ã€ããŠããã¹ã | Futurismo
åäžã¯ã©ã¹ ãšãããšããããã€ã³ã. 芪åã®é¢ä¿ã§è¡šçŸã§ããã°ãã. Parent-ChildãšããããŒã¯ãŒãããã€ã³ã. å¥å, ãã©ã«ããã¿ãŒã³. ãã©ã«ãã«ã¯ãã©ã«ããšãã¡ã€ã«ããã. ãã£ã¡ã®ååã®ãããããããã, èŠãããã.
ðšDecorator Pattern
ãµãã¯ã©ã¹åã§ã¯ãªãå§è²ã«ãã, ã¯ã©ã¹ã«æ°ããæ©èœãè¿œå ãã.
ãã€ã³ãã¯, ãªããžã§ã¯ãã®å§è²æ¹æ³ã,
- éçŽã§ã¯ãªããŠã³ã³ããžã·ã§ã³
- ç¶æ¿ã§ã¯ãªããŠã³ã³ããžã·ã§ã³
LinkedList æ§é .
- ðç¶æ¿ããå§è²
- Decorator ãã¿ãŒã³ - Wikipedia
- åçã«æ©èœè¿œå !Java 㧠Decolator ãã¿ãŒã³ãå®è£ ããŠã¿ã | Futurismo
ðšFacade Pattern
è€æ°ã®ã¯ã©ã¹çŸ€ãããªããµãã·ã¹ãã ã«ã¢ã¯ã»ã¹ããããã®ã€ã³ã¿ãã§ãŒã¹ãæäŸãã. ç°ãªããµãã·ã¹ãã ãåçŽãªæäœã ããæã£ã Facade ã¯ã©ã¹ã§çµã³, ãµãã·ã¹ãã éã®ç¬ç«æ§ãé«ããäºãç®çãšãã. facade ãšã¯, æ£é¢ãšããæå³.
ðšProxy Pattern
ãªããžã§ã¯ããžã®ã¢ã¯ã»ã¹ãããã¯ããããã®ä»£çãªããžã§ã¯ããæäŸãã. Proxy ã¯è±èªã§ä»£ç人.
æ¬ç©ã®ãªããžã§ã¯ãã«ã¢ã¯ã»ã¹ãããŸãã«ã¯ãã·ã§ã³ã眮ãããšã§, ããã«æ©èœè¿œå ã§ãã.代çãã©ã¹ã¢ã«ãã¡ã®æ©èœããã€.
-
ãã°
-
ãã¬ãŒã¹
-
ãã£ãã·ã¥
-
ã¢ãã¯
-
Adapter, Facade, Proxy ãã¿ãŒã³ã®éãã®ã¡ã¢ | Futurismo
ðšFlyweight Pattern
äžåºŠçæããã€ã³ã¹ã¿ã³ã¹ã¯ããŒãªã³ã°ããŠããå¿ èŠãªãšãã«åãåºããŠäœ¿ã.
ãªãœãŒã¹ã³ã¹ãåæžã®ããã®ðãã£ãã·ã¥ãšãã£ãŠããã.
- Flyweight ãã¿ãŒã³ - Wikipedia
- Java ã®ãŠãŒãã£ãªãã£ã¯ã©ã¹ã¯ã·ã³ã°ã«ãã³ãã¿ãŒã³/ ãã©ã€ãŠã§ã€ããã¿ãŒã³ã§å®è£ ãã | Futurismo
ðšSingleton Pattern㯠ãã©ã€ãŠã§ã€ããã¿ãŒã³ãšåãããŠå©çšãããããšãããã. ç¹åŸŽã¯,
- private 㪠å€æ°ã« ãªããžã§ã¯ããä¿å.
- ãªããžã§ã¯ããååšããã°, getInstance ã§æž¡ã.
- ãªããžã§ã¯ããååšããªããã°ãªããžã§ã¯ããäœæã㊠getInstance ã§æž¡ã.
wikipedia ãã説æåŒçš.
ãã®æç¹ã§å¯Ÿè±¡ã®ã€ã³ã¹ã¿ã³ã¹ãçæãããŠããªãå Žå
- 察象ã®ã€ã³ã¹ã¿ã³ã¹ãæ°ãã«çæãã.
- çæããã€ã³ã¹ã¿ã³ã¹ãããŒã«ãã (èšãæãããš, ã¡ã³ãã®ã³ã³ãããªããžã§ã¯ãã«æ ŒçŽãã).
- æãããã€ã³ã¹ã¿ã³ã¹ãè¿ã.
察象ã®ã€ã³ã¹ã¿ã³ã¹ãæ¢ã«çæãããŠããå Žå
- 察象ã®ã€ã³ã¹ã¿ã³ã¹ãããŒã«ããåŒã³åºã.
- 察象ã®ã€ã³ã¹ã¿ã³ã¹ãè¿ã.
æ¯ãèãã«é¢ãããã¶ã€ã³ãã¿ãŒã³
ðšCommand Pattern
åäœãè¡šçŸãããªããžã§ã¯ã.
åäœãšããã«äŒŽããã©ã¡ãŒã¿ãã«ãã»ã«åãããã®.
- links
- refs.
- æç¶ãã«å¿ èŠãªãã©ã¡ãŒã¿ã®äžææ ŒçŽå ŽæãšããŠäŸ¿å©.
- é¢æ°åŒã³åºãã®ããã®ãã©ã¡ãŒã¿ãéããŠ, åŸã§äœ¿çšããããã«ã³ãã³ããä¿åããŠããããšãã§ãã.
- ä¿åãããããŒã¿æ§é ã«å¯Ÿããè¿œå , åé€ãå¯èœã«ãªã.
- ã³ãã³ãã®çæãšå®è¡ã®ã¿ã€ãã³ã°ã®åé¢.
ðšChain of Responsibility
責åãæããããªããžã§ã¯ãã® Chain ã« èŠæ±ãæž¡ããŠãã.
èŠæ±ã¯,
- ãã®ãªããžã§ã¯ãã§åŠçã§ããã°ããã§åŠçãã
- ãã®ãªããžã§ã¯ãã§åŠçã§ããªããã°, 次ã®ãªããžã§ã¯ãã«æž¡ã.
ðšInterpreter
æååãããªãæ§æãæ§æ解æã(Interprete), æ§æãè¡šçŸãããªããžã§ã¯ãæ§é ãšããšã®æååãé¢é£ä»ãã.
ðšIterator Pattern
ãªããžã§ã¯ãã®éå (ããŒã¿æ§é , ã³ã³ãã) ããããšã, ãã®éåã®å éšæ§é ã¯ã«ãã»ã«åãããŸãŸã§èŠçŽ ã«å¯ŸããŠé ã«ã¢ã¯ã»ã¹ããæ¹æ³ãæäŸãã.
- ã€ãã¬ãŒã¿ - Wikipedia
- Iterator ãã¿ãŒã³ - Wikipedia
- Java 㧠Iterator Pattern ãå®è£ ããŠã¿ã | Futurismo
ã³ã³ãããªããžã§ã¯ãã®èŠçŽ ãåæããæ段ãç¬ç«ãããããšã«ãã£ãŠã³ã³ããã®å éšä»æ§ã«äŸåããªãå埩åãæäŸããããšãç®çãšãã.
èšèªã§ãµããŒãããŠããããšãããã. æ¡åŒµ for æ, for-each æãªã©ãšåŒã°ãã.
èªåã§å®è£ ããããã, èšèªã«é Œãã»ãããã.
Java
Collection ãã¬ãŒã ã¯ãŒã¯ã§ã¯, å埩åãå©çšã§ãã.
List<Integer> list = LinkedList<Integer>
for (int i; list) {
System.out.println (i);
}
Iterator ã€ã³ã¿ãã§ãŒã¹ãå®è£ ããããšã§èªåã®ã¯ã©ã¹ã«ã€ãã¬ãŒã¿ãé©çšã§ãã.
Ruby
Enumerable ã¢ãžã¥ãŒã«ã Mix-in ãã.
ðšMediator
è€æ°ã®ãªããžã§ã¯ããçžäºäœçšãããå Žåã«, ãäºãã®ãªããžã§ã¯ãå士ãçŽæ¥åç §ããããšããªããããçžäºäœçšãã®ãã®ããªããžã§ã¯ããšããŠå®çŸ©ãã.
ðšMemento
ãªããžã§ã¯ãã®ç¶æ ãä¿åããŠãã, å ã«æ»ããããã«ããŠãã.
ãªããžã§ã¯ãã以åã®ç¶æ ã« (ããŒã«ããã¯ã«ãã) æ»ãèœåãæäŸãã.
ðšObserver Pattern
ãããªããžã§ã¯ãã«äŸåããè€æ°ã®ãªããžã§ã¯ããããå Žåã«, 被äŸåãªããžã§ã¯ãã®ç¶æ å€åã, äŸåãªããžã§ã¯ãã«éç¥ãã.
Ruby ã§ã¯ã©ã€ãã©ãªããã.
ã€ãã³ããªã¹ã.
âPublisher-Subscriberãã¿ãŒã³ãšãããããã, ããããŠããã ãã§å¥ãã®ãªæ°ããã. Pub/Subãã¿ãŒã³ã¯Prod/Consãã¿ãŒã³ã®éšåã§ãã䞊è¡ããã°ã©ãã³ã°ã«é¢ãã.
ðšState Pattern
ã¹ããŒããã¿ãŒã³.
ç¶æ ã«å¿ããŠãªããžã§ã¯ãã®æ¯ãèããå€æŽããããšãã«, æ¯ãèããå¥ãªããžã§ã¯ãã«ã«ãã»ã«åãã.
- State ãã¿ãŒã³ - Wikipedia
- ç°¡æœãã¯åãªã!Ruby ã§ã¹ããŒããã¿ãŒã³ (State Pattern) ãå®è£ ãã | Futurismo
- æç¶ãåã»ãªããžã§ã¯ãæååã»é¢æ°å 3 ã€ã®ãã©ãã€ã ã§ã¹ããŒããã¿ãŒã³ (Java) | Futurismo
see also. ðç¶æ 管çæŠè«
ðšStrategy Pattern
ã¢ã«ãŽãªãºã ãã«ãã»ã«åããŠ, ã¢ã«ãŽãªãºã ã亀æå¯èœã«ãã. ã²ãšã€ã®å ¥åããŒã¿ã«å¯ŸããŠ, ã¢ã«ãŽãªãºã æ¯ã«ç°ãªãçµæãåºåãã.
- Strategy ãã¿ãŒã³ - Wikipedia
- å§è²ã®ãŸãšããš Strategy ãã¿ãŒã³ã®å®è£ (Java) | Futurismo
- Effective Java ã«ã®ã£ãŠãã ãšã¬ã¬ã³ã㪠Enum ã®äœ¿ãæ¹ã¡ã¢ | Futurismo
ã¢ããªã±ãŒã·ã§ã³ã§äœ¿çšãããã¢ã«ãŽãªãºã ãåçã«åãæ¿ããå¿ èŠãããéã«æçš.
- Android
- Windows
- Linux
ååã®ã€ãããã¯xxxStrategyãå€ã.
å€æŽãèæ ®ããŠèšèšããã¢ãããŒã
ãªããžã§ã¯ãæèã®ãããããåŒçš.
- å€æŽå 容ãäºæž¬ããã®ã§ã¯ãªããŠ, ã©ãã«å€æŽãçºçããã®ããäºæž¬ãã
- å®è£
ãçšããŠããã°ã©ãã³ã°ããã®ã§ã¯ãªããŠ, ã€ã³ã¿ãã§ãŒã¹ãçšããŠããã°ã©ãã³ã°ãã.
- ã¯ã©ã¹ç¶æ¿ããã, ãªããžã§ã¯ãã®éçŽãå€çšãã.
- æµåçèŠçŽ ãã«ãã»ã«åãã.
switch æãå€çšããã, ã°ãã£ã°ãã£ã«ãªã£ãŠããã赀信å·. switch æã¯æµåçèŠçŽ ãªã®ã§, ãã®éšåãã¯ã©ã¹ã«åé¢ããŠã«ãã»ã«åãã.
ã¯ã©ã¹ã«åé¢ããéã¯, ç¶æ¿ããããŠéçŽãå€çšãã.
Effective Java ãã
p101 æŠç¥ãè¡šçŸããããã«é¢æ°ãªããžã§ã¯ãã䜿çšãã
- æŠç¥ãçŸãã€ã³ã¿ãã§ãŒã¹ãçšæ
- åã
ã®å
·è±¡æŠç¥ã«é¢ããŠãã®ã€ã³ã¿ãã§ãŒã¹ãå®è£
ããŠããã¯ã©ã¹ãå®çŸ©.
- å ·è±¡æŠç¥ãäžåºŠããå©çšãããªããªãã°, ç¡åã¯ã©ã¹ã§äœæ
- ç¹°ãè¿ãå©çšããããªãã°, public static final ã® ãã£ãŒã«ã or static factory method ãéããŠæäŸ.
ðšTemplate Method
ðç¶æ¿(Inheritance)ã®ããš.
ã¢ã«ãŽãªãºã ãè€æ°ã®ã¹ãããã«å解ã, ããããã®ã¹ããããæœè±¡ã¡ãœããã«ãã.
åã¹ãããã§ã®ã¡ãœããã®å®è£ ã¯ãµãã¯ã©ã¹ã§å®çŸ©ãã.
ã·ã¹ãã ã®ãã¬ãŒã ã¯ãŒã¯ãæ§ç¯ããããã®æ段ãšããŠãã掻çšããã.
Factory Method ãã¿ãŒã³ã¯, å éšã« Template Method ãã¿ãŒã³ãå å«ããããšãå€ã
class A
def execute ()
raise "to be implemented"
end
end
class B < A
def execute ()
end
end
class C < A
def execute ()
end
end
ðšVisitor Pattern
è€æ°ã®ãªããžã§ã¯ããããªããªããžã§ã¯ãæ§é ããããšãã«, ããããã®ãªããžã§ã¯ãèŠçŽ ã«åŠçãè¿œå ãŸãã¯ãªããžã§ã¯ãèŠçŽ ã®åŠçãå€æŽãããã, Visitor ã¯ã©ã¹ãçšæãã.
Java 㧠Visitor Pattern ãå®è£ ããŠã¿ã | Futurismo
ã ãããããªææ³ãèãã€ããã®ã ãã??ãã¶ã€ã³ãã¿ãŒã³ã£ãŠããããâã
ããã¯ããã«ãã£ã¹ããã(ðå€éãã£ã¹ããã)ãšåŒã°ããææ³.
GoF以å€ã®ããµã€ã³ãã¿ãŒã³
ðšAbstract Server pattern
- äžè¬çã«ãµãŒããŒããµãŒãã¹ã®èšèšã«é¢ãããã¿ãŒã³ã®äžã€ã§ãå ·äœçãªå®è£ ã«äŸåããã«ãµãŒããŒã®æäœã管çãè¡ãããã®æœè±¡åãæäŸããŸã.
- DIP/OCP/LSPãã¿ããã·ã³ãã«ãªäŸ.
- Abstract Factoryãšã¯é¢ä¿ãªã. ååã䌌ãŠããã ã. ã©ã¡ãããšãããšTemplate/Strategy Pattern.
- ãã GoFã«äŒŒããã¿ãŒã³ãæ¢ãããã, åã«ããã¯æœè±¡ãšå®è£ ãåãããšãã䞻匵ããŠãªããã¿ãŒã³ã .
ãã«ãã¹ã¬ããããã°ã©ãã³ã°ãã¿ãŒã³
ðšãã«ãã¹ã¬ããããã°ã©ãã³ã°ãã¿ãŒã³ãž.
ãã¶ã€ã³ãã¿ãŒã³Topics
ã«ãã»ã«åã®èŠç¹ã§æŽç
ã«ãã»ã«åãããŒã¿é èœãšããã®ã¯ç矩ã®å®çŸ©.
ã«ãã»ã«åãšã¯ãããããã®ãé èœããããš.
- ããŒã¿
- ã¡ãœãã
- å®è£
- 掟çã¯ã©ã¹
- èšèšã®è©³çŽ°
- å®äœåã®èŠå
- å
æµåçèŠçŽ ãæ¢ãåºããŠã«ãã»ã«åãã. å§è²ã¯æ段.
ãã®èŠ³ç¹ãã, ãã¶ã€ã³ãã¿ãŒã³ããšããçŽããš,
æµåçèŠçŽ | Pattern |
---|---|
ã¢ã«ãŽãªãºã | Strategy |
ç¶æ | State |
æ¯ãèã | Decorator |
ãã¿ãŒã³ããã, å | Visitor |
åäœ, èŠæ± | Command |
å®è£ | Bridge |
å€åãžã®åå¿ | Observer |
çžäºäœçš | Mediator |
çæ | Factory Method, Abstract Factory , Prototype |
äžææ§ | Singleton, Flyweight |
æ§é ã®çæ | Builder |
éåã®å·¡åæ§é | Iterator |
ã€ã³ã¿ãã§ãŒã¹ | Adapter |
ã·ã¹ãã | Facade |
èšèšã®è©³çŽ° | Template Method |
ãã¿ãŒã³ã§èãã
ãªããžã§ã¯ãæåã®ããã 13 ç« ãã.
- ãã¿ãŒã³ã®æŽãåºã ⊠ãã¡ã€ã³ã«ååšãããã¿ãŒã³ããŸãã¯åæ.
- ãã¿ãŒã³ã®åæã»é©çš ⊠1-4 ãç¹°ãè¿ã.
- ãã¿ãŒã³ã®äžŠã¹æ¿ã
- ãã¿ãŒã³ã®éžæãšèšèšã®æ¡åŒµ
- è¿œå ã®ãã¿ãŒã³ã®æŽãåºã
- ç¹°ãè¿ã
- èšèšã®è©³çŽ°
é¢æ°åèšèªãšãã¶ã€ã³ãã¿ãŒã³ã®é¢ä¿
- ã©ã ãåŒã§ Command ãã¿ãŒã³ã§æžãããã³ãŒããã·ã³ãã«ã«ãã ~ ã©ã ãåŒäœ¿ããžã®ç¬¬äžæ© (1/5):CodeZine
- Design Patterns in Haskell : Inside 206-105
-
Haskell ã§ã®çœ®ãæã
Pattern Desc Strategy â é«éé¢æ°ãæž¡ã State à ç¶æ ããããªã Momento à ç¶æ ãæããªã
-
LISPãã¯ããšãã¶ã€ã³ãã¿ãŒã³ã®é¢ä¿
ã©ã¡ãããã¿ãŒã³ã®ã«ãã»ã«åããã¢.
Opinions
Insights
âšãã¶ã€ã³ãã¿ãŒã³ã¯ã³ã³ãµã«ãã¬ãŒã ã¯ãŒã¯ã®ãããªãã®
ãœãããŠã§ã¢æ¥çã§ã¯æåãªãã¶ã€ã³ãã¿ãŒã³ãã¢ãŒããã¯ãã£ãã¿ãŒã³.
ããžã«ã«ã·ã³ãã³ã°ãã³ã³ãµã«ãã£ã³ã°ãã¡ãŒã æ¥çã§æåãªMECEããã©ãããã¹ãã©ã¯ãã£ãªã©ã®ãã¬ãŒã ã¯ãŒã¯.
ããã¯ã©ã¡ããåãšããåãããšããã£ãŠããæ°ããã. ãããã®ãœãããŠã§ã¢ã®äººéã§ã©ãããã¬ãŒã ã¯ãŒã¯ãšãããšçžé ããããªå°è±¡ã ã£ãã, ãªãã åãªã倧奜ããªãã¶ã€ã³ãã¿ãŒã³ã®å»¶é·ãããªãã.
ð€ãã¶ã€ã³ãã¿ãŒã³ãé§ãåºããšã³ãžãã¢ãå匷ããããšã¯æ°äººã³ã³ãµã«ãããžãã¹ãã¬ãŒã ã¯ãŒã¯ãæèšããããšã«äŒŒãŠãã
GoFãã¶ã€ã³ãã¿ãŒã³ãé§ãåºããšã³ãžãã¢ãå匷ããããšã¯æ°äººã³ã³ãµã«ãããžãã¹ãã¬ãŒã ã¯ãŒã¯ãæèšããããšã«äŒŒãŠãã, ã©ã¡ããå®è·µã§äœ¿ããªã.
ãããã, é§ãåºããšã³ãžãã¢3 幎çãããã®ãšã, ãšã«ãããããå šéšèŠããŠãããRubyãJavaã§å®è£ ããŠããããšããéæããã£ãã, ã³ã³ãµã«è»¢çããããã¬ãŒã ã¯ãŒã¯äžžæèšããå®è·µã®åœ¹ç«ããªæ°ããã.
- ðé§ãåºããšã³ãžãã¢
- âšãã¶ã€ã³ãã¿ãŒã³ã¯ã³ã³ãµã«ãã¬ãŒã ã¯ãŒã¯ã®ãããªãã®
References
ref. ãã¶ã€ã³ãã¿ãŒã³ (ãœãããŠã§ã¢) - Wikipedia
æŠèŠãããããããŒãž
åã¿ç ããã, ãããããã説æ.
å³è§£ã§è§£èª¬ãããŠãã.
ãµã³ãã«ãœãŒã¹ãè±å¯.
Gang Of Four ã®ã€ã³ã¿ãã¥ãŒ
çµå浩ããã®äžŠè¡ã»äžŠåããã°ã©ãã³ã°ã®ãã¿ãŒã³çŽ¹ä»