8/2 ã« Working Effectively with Legacy Code ã®第3回読書会ãè¡ããã¾ãããå¹¹äºã®ãã¨ãããåå è ã®çãããç²ãæ§ã§ããã
ä»å㯠9 ç« ãã 12 ç« ã®éä¸ã¾ã§ã
Chapter 9. I Can't Get This Class into a Test Harness
xUnit ã¨ãã§ãã¹ããæ¸ããã¨ããããã³ã³ã¹ãã©ã¯ã¿ã®å¼æ°ãè¤éã ã£ãããåææ¡ä»¶ãå¿ è¦ã ã£ãããã¦ãç¬ç«ãããã¹ãã³ã¼ãã®ä¸ã§ã¯å®¹æã«ã¯ã¤ã³ã¹ã¿ã³ã¹åã§ããªãã¨ããã·ãã¥ã¨ã¼ã·ã§ã³ã§åãå¾ã対çã«ã¤ãã¦ããããç´¹ä»ãæ å½ã¯ ãã¨ãããid:htada ãããå·æ¾ããã
å人çã«ã¯ï¼ç« ã§ç´¹ä»ããã¦ããææ³ã¯ãä»ã«ããããããªãã«ãã¦ããã¡ãã£ã¨æ¡ç¨ããã®ã«äºã®è¶³ãè¸ãã§ãã¾ããããªãã®ã°ããã§ãªããªãããã©ããnew 㨠delete ã空ä¸ã¢ã¯ãããããã¦ããã¨ããçççã«æ絶ãã¦ãã¾ããã§ããã©(è¦ç¬)ã
ã¾ãããããªæ³¥ç¸ãç·¨ã¾ãªãã¦ãããããã«æåããèãã¦ã³ã¼ãæ¸ããªãã¨ãããªããï¼ãã¨ããæè¨ã ã¨æããã
Chapter 10. I Can't Run This Method in a Test Harness
åãããã¹ããæ¸ããã¨ãããããã¹ããããã¡ã½ããã private ã ã£ããã(å ´åã«ãã£ã¦ã¯å±éºãª)å¯ä½ç¨ãçºçãã¦ãã¾ãå¯è½æ§ããããªã©ã§ããã¹ãã³ã¼ãã®ä¸ããæ°è»½ã«å¼ãã§ã¿ãããã«ãããªãã¨ããã·ãã¥ã¨ã¼ã·ã§ã³ã«ã¤ãã¦ãå·è¥¿ããæ
å½ã
å·è¥¿ããã¯ååãæ¨çå°èª¬ã¡ã½ããã¨ãããã¨ã§ã¨ã¦ãå³ã®ãããã¬ã¼ã³ã ã£ãã®ã ãã©ãä»åããã¬ã¼ã·ã§ã³ã¨ãã¾ã¨ããã®ã¤ãããããæ¼ããããããããå
容ãå·è¥¿ã¡ã½ããã確ç«ããã¦ããã¨ãããã£ã±ãã®åãåæ¥ã®å¤ä¸ï¼æï¼æã«è³æãä½ã£ã¦ããã¨èªç¶ã¨ãããªãã¨ã®ãã¨ãªã®ã§ãå¿ããææã«æ
å½ãæ¼ãã¤ããã®ãå·è¥¿ã¡ã½ããçºåã®ååæ¡ä»¶ã¨ãããã¨ã§ï¼¦ï¼¡ï¼
private ã¡ã½ããã®ãã¹ãã¯ååãè°è«ã®å¯¾è±¡ã«ãªã£ãããã®ã¨ãã¯ã private ã¨ãããã¨ã¯ã¤ã³ã¿ã¼ãã§ã¼ã¹ãããªããã§ããï¼ãããã®ãã¹ãã£ã¦å¤ãããï¼ãã¨ããæ¹åã®è©±ã ã£ããï¼ï¼ç« ã§ã¯ãããã§ãã©ããã¦ããã¹ããããå ´åã«ã©ããããããæ±ã£ã¦ãã¦ãçµè«ããè¨ãã¨ã protected ã«å¤æ´ãã¾ãããã
ãã®èè
ã¯ãã¹ãåç主義è
ãããã®ã§ããã¹ãã®ãããªãã«ãã»ã«åãå´©ããã¨ãåããªããã¾ãã«ãã»ã«åãæ段ã®ä¸ã¤ã«éãããä¸æ¹ã³ã¼ãã«ãã¹ããä»ãã¦ãããã¨ã¯ç´æ¥éæ¥ã«æ§ã
ãªã¡ãªãããçãã®ã§ãä¸çã¯ããã¨æããããprivate ã«ããçç±ããã£ã¦ private ã«ãã¦ãã(ãããããªã)ã®ãã»ãã»ãå¤ãã¦ãã¾ã£ã¦ãããã ãããã¨ããéåæã¯ã©ããã¦ãæ®ãã
ã¾ããåå id:t-wada ããããæãã£ãã TDD ã¯ããããªãã¨ã³ã¼ããæ¸ããªã(å®è£
ãã³ã¼ãã«è½ã¨ããªã)人ã®ããã®ãã®ãã¨ããç¥è¨ããããã¨ãprivate ã¯ãã¯ã private ã®ã¾ã¾ãã¹ããããéè¦ãå¤ãã®ã§ã¯ãªããã¨ãæãã
ã Java ã 㨠package scope (å½ private) ã使ãã¨ããæãããããçãªå ´å½ãããªææ³ã¯ããããã¦ãã¦ä»¥å¤ã®ä½è
ã§ããªãã®ã§ããã¯ãè¨èªããã¹ãç¨ã®ã¹ã³ã¼ã(ã³ã³ãã¤ã©ãªãã·ã§ã³ãèµ·åãªãã·ã§ã³ã§æå¹ç¡å¹ãæå®ã§ãã)ããµãã¼ãããã¹ããªã®ã§ã¯ãªããã¨å¼·ãæããã
Chapter 11. I Need to Make a Change. What Methods Should I Test?
ãã¹ãã³ã¼ãã¯æ¸ããªãããããªãã¨ã¯æã£ã¦ãããå¤æ´ããã¡ã½ããã«ã¤ãã¦ãã¹ããæ¸ããã ããã足ããªããã¨ãããã£ã¦ãããã§ãå
¨ã¦ã®ã¡ã½ããã網ç¾
ãããã¹ããæ¸ãã¦ããæéã¯ãªããã©ãã«ãã¹ããæ¸ããããããã ããâ¦â¦ã¨ããã·ãã¥ã¨ã¼ã·ã§ã³ãèªåã§æ
å½ã
ååããä»æ§ãè¦ããå®è£
ãæãæµ®ãã¶äººã« TDD ã¯ç¡çãã¨ãããã¨ã¯ãèªåã®æ¸ãã³ã¼ãã¯å¸¸ã«å¿
ã Legacy Code ãã¨ããçµè«ãåºã¦ãã¾ã£ãããããªèªåã¯ã Legacy Code ã®ã©ãã«ãã¹ããæ¸ãã°ããããã¨ãã話é¡ãæ±ã£ã¦ããï¼ï¼ç« ã»ï¼ï¼ç« ãã©ãããèªãã¹ãã§ãããã¨ãããã¨ã§æãæãã¦ã¿ãããã ã
Effect Sketch ã¨ããå½±é¿ã®ä¼æãåæããããã®ãã¼ã«ãç´¹ä»ããã¦ãããã¤ã³ã¹ã¿ã³ã¹å¤æ°ãã¡ã½ããã«ãªã©ã¤ãã¦ããããã®ãå¥ã®ãã®ã«å½±é¿ãåã¼ãå ´åã«ç¢å°ãå¼ãããã®ã°ã©ãã«ãã£ã¦æãå½±é¿ãåãããã®ãç¹å®ããããä¾åæ§ã解æ¶ããã»ããè¯ãç®æã®ç¹å®ã«ç¨ããâ¦â¦ã®ã§ããã°è¯ãã£ãã®ã ãã
ãµã³ãã«ããã°ã©ã ã使ã£ã¦å®éã« Effect Sketch ãããã¤ãæ¸ãã¦ã¿ãã®ã¯ãããã第ï¼å¼¾ãæ¸ããã ãã第ï¼å¼¾ãã³ã¼ãã®ããã«ãã¹ããæ¸ãã°ãããï¼ãeffect sketch æ¸ããã ãã§ä½¿ã£ã¦ãªããã©ãã第ï¼å¼¾ãã³ã¼ãã®éè¤è§£æ¶ãããï¼ãeffect sketch æ¸ããã ã(ryããããå³ééã£ã¦ããï¼ãã¨ãããã¡ãã¨ããæ¥ã¦åº§ããªããæ£åº§ã ãæ£åº§ã
èªæ¸ä¼ã§ã¯ãã£ã¨ã¾ããã«ãã©ãã¼( effect sketch ãããæ¸ãã°èªç¶ã«ãã®çµè«ãå°ããã®ã§ã¯ãã¨ã)ãã¦ããã®ã§ãå®å¿ããWEwLC Wiki の資料ã«ã¾ã¨ãã¦ããã®ã§ãããèå³ãããã°ãã¡ããã
éçºããã¨ãã®è¨è¨ãã¼ã«ã¯ããããããããã©ããã§ã«åå¨ãã¦ããã³ã¼ãããã©ãã«ãã¹ããæ¸ãã°ãããã¨ãã観ç¹ã§åæãããã¼ã«ã¯(寡èãªã ããããããªãã)ä»ã«ç¥ããªãã®ã§ããããããã¼ã«ã¯ã¨ã¦ãæç¨ã ããã¨ããæå¾
ã¯ããã®ã ãã©ããã®ç¨åº¦ã®ç´¹ä»ã§ã¯ãããã«å³ããããããã ããã®å¼·ãå³å¯ãªäººããã® Effect Sketch ãè²ã¦ã¦(ããéããªãç¯å²ã§)大ãã伸ã°ãã¦ãããã°è½ãåºãå¯è½æ§ã¯ãªããªãããããããªããã¨ããæ°ã¯ããã®ã ãã©ã
ãã®ç« ã¯ããã³ãã©ããã®å¤ããµã³ãã«ããã°ã©ã ãè¦æã®ä¸ã¤ã ããã
ï¼ã¤ç®ã®ããã°ã©ã ã¯ã Java 㧠C++ ã®ã³ã¼ããçæãããã¨ããããµã³ãã«ã«ãããé¸ã¶ã¨ããã®ã¯æ¬å½ã«ã©ããªã®ï¼ãã¨æããã«ããããªãããï¼ã¤ç®ã¯ããã®ããã°ã©ã ãã¡ã³ããã¦ããã¨ããã渡ãããæ¥ã«ã¯ã³ã³ãã¥ã¼ã¿æ¥çãé¸ãã èªåãåªããããªãã ããï¼ãã®ããã 20 è¡ã¡ããã§ããã»ã©ã®ç ´å£åãããã¨ãããã¨ã¯ãå
¨ä½ã¯ãã£ããâ¦â¦ï¼ï¼ããããã©ã¡ãã«ã¤ãã¦ãããããªã«ã²ã©ããµã³ãã«ãæ¡ç¨ããçç±ããã©ãã©ã¨è¨ã訳ãã¦ããã®ãç´ æµã
ã¾ããã®ç« ã«éããããã®æ¬ã®ãµã³ãã«ããã°ã©ã ã¯ããããèè
ãã³ã³ãµã«ã¿ã³ãã¨ãã¦ç«æ¶ãã®ç¾å ´ã«æ°å¤ãé§ãåºãããä¸ã§ãè¦ã¦èãã¦è¦ããã å®éã® Legacy Code ãå
ã«ãªã£ã¦ããã®ã ããã¨æ¨æ¸¬ãã(ãã¹ãã³ã¼ããã«ã¡ã©å£ãã¡ãã£ãï¼ãã¨ã)ãå¿
è¦ä»¥ä¸ã«äººéãããã¦ãªã«ãã¨ãããããã
Chapter 12. I Need to Make Many Changes in One Area. Do I Have to Break Dependencies for All the Classes Involved?
ï¼ï¼ç« ã¾ã§ã¯æ¹å¤ã®å¿ è¦ãçããã¨ãã«ã³ã¼ããã©ã®ããã«æ¹å¤ããããã¹ããæ¸ãããããããç´¹ä»ãã¦ããã®ã ããï¼ï¼ç« ã¯æ¹å¤ã®éãå¤ããã¦ã¨ã¦ã追ãã¤ããªããã³ã¼ãã¯å½±é¿ã®é£éã§è¤éã«çµ¡ã¿åãããã¦ãããã©ãããããããã !?ãçã·ãã¥ã¨ã¼ã·ã§ã³ãããã¡ããæ å½ã
ãã£ãã® Effect Sketch ãä¾åæ§ã®è§£æ¶ã®ããã«ç¨ããã¨ããå
容ãªã®ã ãâ¦â¦ããããç´å¾ãã«ããé¨åãå¤ãã£ããï¼ï¼ç« ããããªèª¿åã ã£ãããã ããããã®ç¶ãããããªã£ã¦ãã¾ãã®ã¯ç¡çããªãã®ãããããªããã©ã
ãã®ç« ã¯æ¬æ¥ã¨ã¦ãéè¦ãªè¯ããã¼ããæã£ã¦ããã¨æãã®ã§ãããã¡ãã£ã¨ãã£ããçå±ãæ¸ãã¦æ¬²ãããªãã¨æãããã¦ãã¾ã£ãã
id:t-wada ããæ
å½ã® 13 ç« ã楽ãã¿ã«ãã¦ããã®ã ããã©ãæ®å¿µãªããï¼ï¼ç« ã®éä¸ã§ã¿ã¤ã ã¢ãããã¾ãé½åº¦é½åº¦ã®è°è«ãããã ãçãä¸ãã£ã¦ã®çµæãªã®ã§ä»æ¹ãªãã¨ããã
ä»ã®äººãããããæ¯åæ¸ãã¦ããã¨æããããã®æ¬ã®å
容ããããã¨ãªããèªæ¸ä¼ã®è°è«ãã¨ã«ããèå³æ·±ããå®å¡ã«å¤§ããå±ããªãã£ãã®ã¯ã¡ãã£ã´ãæ®å¿µã
ãã®èªæ¸ä¼ã«åå ãã¦ãã人ã¯ã¿ããªã·ã£ã¤ãªã®ã§ããã°ã¨ã³ããªå°ãªãã宣ä¼å°ãªããªã®ãåå ï¼ãè¦ã¤ãã奴貼ã£ã¦ãããã
- http://d.hatena.ne.jp/htada/20080803/1217787498
- http://www.dodgson.org/omo/t/?date=20080802#p01
- http://d.hatena.ne.jp/kunit/20080803#1217689379
æ親ä¼ã§ã¯ä¸é¨ã®äººãâ¦â¦ããä»åã¯èªéãããããã¿ããªãããå¨ãã«æªããåéã座ã£ã¦ãªãã£ãã®ãåãå¥ããã®ããã