Emergent design with phpspec

Download Emergent design with phpspec

Post on 10-May-2015

5.513 views

Category:

Technology

3 download

Embed Size (px)

DESCRIPTION

Where does design fit in agile projects? What is refactoring and what isn't refactoring? What is the relationship between design and refactoring, and design and architecture? In this talk we will clarify these and other questions around emergent design and how a TDD/BDD tool like phpspec can help you with the process. We will look into how phpspec helps uncover smelly code and point in the direction of refactoring techniques to guide the design of flexible, testable and easy to extend object oriented PHP code enabling developers to focus on whats more valuable for the customer at all times and re-steer the direction of the product.

TRANSCRIPT

<ul><li>1.by@_mdemergentdesignwith</li></ul> <p>2. IworkhereIcontributehereItweethere @_mdMarcelloDuarte 3. its2007 4. @padraicb@tswicegood 5. aportforrspec 6. !==http://earthymoon.deviantart.com/art/Elephant-png-122633500 http://sonylisation.deviantart.com/art/Ruby-Nr-2-207831683 7. bowling.score.should eq(0) 8. inrubyeverythingisanobjectandallobjectsareopenbowling.score.should eq(0) 9. inrubyeverythingisanobjectandallobjectsareopenhttp://www.ickr.com/photos/owenbooth/126288240/bowling.score.should eq(0) 10. inrubyeverythingisanobjectandallobjectsareopenhttp://www.ickr.com/photos/owenbooth/126288240/bowling.score.should eq(0) 11. $this-&gt;spec($bowling-&gt;getScore())-&gt;shouldEqual(0);PHPSPECEARLYSYNTAXEXAMPLE 12. http://www.ickr.com/photos/jamesrbowe/8403688026/amber... red... green... 13. md@bossa:tests $ phpunit .PHPUnit 3.7.14 by Sebastian Bergmann.PHP Fatal error: Class Customer not foundin /Users/mduarte/Documents/NoSync/Lab/phpunit/tests/CustomerTest.php on line 8Fatal error: Class Customer not found in /Users/mduarte/Documents/NoSync/Lab/phpunit/tests/CustomerTest.php on line 8 14. yougottabemockingme! 15. public function testUpdateWithEqualTypes(){$installer = $this-&gt;createInstallerMock();$manager = new InstallationManager(vendor);$manager-&gt;addInstaller($installer);$initial = $this-&gt;createPackageMock();$target = $this-&gt;createPackageMock();$operation = new UpdateOperation($initial, $target, test);$initial-&gt;expects($this-&gt;once())-&gt;method(getType)-&gt;will($this-&gt;returnValue(library));$target-&gt;expects($this-&gt;once())-&gt;method(getType)-&gt;will($this-&gt;returnValue(library));$installer-&gt;expects($this-&gt;once())-&gt;method(supports)-&gt;with(library)-&gt;will($this-&gt;returnValue(true));$installer-&gt;expects($this-&gt;once())-&gt;method(update)-&gt;with($this-&gt;repository, $initial, $target); 16. @_md@everzet 17. goals{funtoworkwith 18. goals{developmenttoolfuntoworkwith 19. goals{developmenttoolletsnotgetinthewayfuntoworkwith 20. goals{enforce(mockist)TDDdevelopmenttoolletsnotgetinthewayfuntoworkwith 21. goals{enforce(mockist)TDDdoitthePHPwaydevelopmenttoolletsnotgetinthewayfuntoworkwith 22. {"require-dev": {"phpspec/phpspec": "2.0.*@dev"},"config": {"bin-dir": "bin"},"autoload": {"psr-0": {"": "src"}}} 23. $ bin/phpspec describe Some/Class$ bin/phpspec describe Some/Class 24. $ bin/phpspec describe Some/Class$ bin/phpspec run$ bin/phpspec describe Some/Class$ bin/phpspec run 25. $ bin/phpspec describe Some/Class$ bin/phpspec runphpspec generators$ bin/phpspec describe Some/Class$ bin/phpspec runphpspec generators 26. $ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators$ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators 27. $ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators$ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators 28. $ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators$ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators 29. littledemo 30. emergentdesign 31. designemergeiterativelydrivenbytests 32. designis... 33. designsoftwareis... 34. designsoftwareistodescribehowweresolvingaproblem 35. calculatecostvarianceforaperiod 36. calculatecostvarianceforaperiodPeriod 37. firstlearndesign,thenemergentdesign 38. Key in making great and growable systems is todesign how its modules communicate[andnot]whattheirpropertiesandbehavioursshouldbe.MessagingViewpointsResearchInstituteSource-BonnieMacbirdURL-http://www.vpri.org 39. messaging 40. $this-&gt;person-&gt;getCar()-&gt;getEngine()-&gt;ignite(); 41. focusonmessagingmakesthecodeflexible 42. $this-&gt;person-&gt;startCar(); 43. describinghowobjectsinteracttosolveproblemswhichroles,responsibilitiesandmessagesdesignsoftwareis 44. bigdesignupfront 45. ITSHARDTOCHANGELATER. 46. WENEEDTOTHINKABOUTTHINGSBEFOREDEVELOPING. 47. WENEEDTOMAKESUREWEDONTMISSANYTHING. 48. THISISJUSTTHEWAYWEDOIT. 49. relativecostofrepaircosttimeanalysis design code test deploy rework$ 50. yagni 51. 61%oftherequestedfeaturesareactuallydelivered[Standish Group Report 06] 52. 27%ofrequestedfeaturesareactuallyused 53. 5% to 10%areresponsibleforrealisingthebenefitsenvisioned 54. designforthehighpriorityitemsandmakeiteasytochangelater 55. describinghowobjectsinteracttosolveproblemswhichroles,responsibilitiesandmessagesinachange-friendlywaydesignsoftwareinagileis 56. easiersaidthandone? 57. testcoderefactor 58. usesimpledesignrulestorefactor1.Alltestsrunandpass2.Removeduplication3.Removeopacity4.Removecomplexity 59. resultsincode1.Testable2.Modular3.Expressive4.Simple 60. lackoftestsbreaksinnerquality1.Viscosity2.Immobility,Rigidity,Fragility3.Unreadable4.Complex 61. simpledesignisgreattodetectsmells 62. simpledesign1.Alltestsrunandpass2.Removeduplication3.Removeopacity4.Removecomplexitysmells1. Anytestssmells?2.AnyDRYsmells?3.Anyopacitysmells?4.Anycomplexitysmells? 63. TestSmells Lackoftests Testsarenotunitary Setupistoocomplex Unclearexercise Morethanoneexpectationinatest Noexpectation Toomanypaths 64. DrySmells Simpleduplication Logicduplication Duplicationofconstant Alternativeclasseswithdifferentinterfaces 65. OpacitySmells Namenotfromdomain Namenotexpressingintent Featureenvy Methoddoesmorethanonething Methodtoolong Primitiveobsession Commentsinthecode MiddleMan 66. ComplexitySmells Unnecessaryelse Unnecessaryif Unnecessaryswitch Toomanyargumentspassed InappropriateIntimacy Workinconstruction Staticcontext 67. usedesignpatternstorefactor 68. creational?behavioural?structural? 69. whatcanhappeninamethod? 70. returnavaluemodifystateprintsomethingthrowanexceptiondelegate{methods 71. returnavaluemodifystateprintsomethingthrowanexceptiondelegate{methodsnotthefinalbehaviour 72. returnavalueprintsomethingthrowanexceptiondelegate{methodsweshouldprobablydelegatethattoo 73. returnavaluethrowanexceptiondelegate{methods 74. designdelegationwithmocks 75. startbydefiningbehaviour 76. internallydelegatetoanothermethod 77. Finally Definenewrole Extractcollaboratorsusingmocks Movebehaviourdefinitiontonewcollaboratortest 78. phpspecemergentdesignsimpledesignandsmellsdesigningcompositionwithmocks 79. MarcelloDuarteIworkhereIcontributehereItweethere @_md 80. Thankyou! 81. QuestionsorComments?wanttolearnmore?bitly.com/inviqa-bdd-training@_md joind.in/8459 </p>