ãã¬ãŒã ã¯ãŒã¯
åå
is-a/has-aé¢ä¿
is-a 㯠ç¶æ¿é¢ä¿. has-a 㯠å å«é¢ä¿ (å§è²).
ðis-aé¢ä¿
ðç¶æ¿(Inheritance)é¢ä¿ãè¡šã代æ¿è¡šçŸ. B is-a Aãšã¯, Bã¯Aã®ãµãã¯ã©ã¹. ã«ãããæ±å.
is-a ä¿¡ä»°ãšã¯, ãªãã§ãç¶æ¿ããã°ãããšããèãæ¹.
ðhas-aé¢ä¿
å å«, 移è²é¢ä¿ã瀺ã代æ¿è¡šçŸ.
ð¡is-aã¯åé¡ã§has-aã¯å解
ref. åæææ³ã®ããã³ïŒãå解ãšåé¡ããã.
- 察象ãåé¡ããŠç解ããæ¹æ³ãis-aé¢ä¿.
- 察象ãããåçŽãªæ§æèŠçŽ ã«å解ããŠç解ããæ¹æ³ãhas-aé¢ä¿.
ãã¢ãã®äŸã§ã¯,
- ãã¢ãã¯éµç€æ¥œåš.
- ãã¢ã is-a éµç€æ¥œåš.
- ãã¢ãã¯éµç€ãæã€.
- ãã¢ã has-a éµç€.
âšis-aã¯ãã©ã«ãã§has-aã¯ã¿ã°
ðWikiã®ã¡ã¢ãæŽçãããšã, ã¿ã°ãšãã©ã«ãã®ã©ã¡ããã€ãããæ©ãããšããããã.
ããã¯, OOPã§ãããšããã®, is-aãšhas-aã®é¢ä¿ã«äŒŒãŠããããšã«æ°ã¥ãã.
- is-aãšã¯, ç¶æ¿é¢ä¿ã§ãããã©ã«ãæ§é .
- has-aãšã¯, 移è²é¢ä¿ã§ããã¿ã°ã«ããã°ã«ãŒãã³ã°.
ããã¡ã¢ãã²ãšã€ã®ãã¡ã€ã«ã«ãããŠã, å¥ã®ãã¡ã€ã«ã«å ¥ãããããšã¯ãããããã. ããã¯OOPã«ãããŠðå€éç¶æ¿ã®åé¡ãšããŠããç¥ãããŠããããšã . ãã®å Žå, ã¿ã°ãã€ãã£ãŠæ å ±ãæŽçããã®ãè¯ã解決æ¹æ³.
ãã å人çã«ã¯, ç©äºãç解ããããšãããšãã«, ãã©ã«ãæ§é ã«ãããããããŠã³ã®ç解ã®ã»ããããã ã¢ãããããã¹ããŒããéã. äžããã¿ããããã.
ðãªããžã§ã¯ãæåã®ããã
OOP ã® 2 倧åå
ãªããžã§ã¯ãæåã®ããããšã¯, ãºããªä»¥äž.
ðæµåçèŠçŽ ãæ¢ãåºããŠã«ãã»ã«åãã
ã¯ã©ã¹ç¶æ¿ããããªããžã§ã¯ãã®éçŽãå€çšãã
åè©/ åè© æœåºæ³
- åé¡é åã«ååšããåè©ãæŽãåºãããããè¡šçŸãããªããžã§ã¯ããçæãã.
- åè©ã«é¢é£ããåè©ãæŽãåºã,ããããè¡šçŸããã¡ãœãããè¿œå ãã
å ±éæ§/ å¯å€æ§ åææ³
- å
±éæ§åæ:
- æéãçµã£ãŠãå€åãã«ããæ§é ãèŠã€ãããã®
- å ±éæ§åæã«ãã£ãŠãŸãšããããæŠå¿µãæœè±¡ã¯ã©ã¹ã«ãã£ãŠè¡šçŸ
- å¯å€æ§åæ:
- å€åããããæ§é ãæŽãåºããã®
- å¯å€æ§åæã§åŸãæµåçèŠçŽ ã¯æœè±¡ã¯ã©ã¹ã®æŽŸçã¯ã©ã¹ã«ãã£ãŠå®è£ ããã
èšèšæé :
- (æœè±¡ã¯ã©ã¹) ãã®ã¯ã©ã¹ãæã€è²¬åããã¹ãŠå šãããã«ã¯ã©ããããªã€ã³ã¿ãŒãã§ã€ã¹ãå¿ èŠã?
- (掟çã¯ã©ã¹) ãã®ç¹å®å®è£ ã®äžã§ã©ãã®ããã«ããŠäžããããä»æ§ãå®è£ ã§ããã®ã?
Jim Coplien ãæå±. p235 第 15 ç« ããæç².
References
- ãªããžã§ã¯ãæåã®æ¬æ (7) ã»ãªããžã§ã¯ãæååæ - Strategic Choice
- å ±éæ§ã»å¯å€æ§åæ (commonality/variavility analysis) - Debuginfo