by@_mdemergentdesignwith
IworkhereIcontributehereItweethere @_mdMarcelloDuarte
it’s2007
@padraicb@tswicegood
aportforrspec
!==http://earthymoon.deviantart.com/art/Elephant-png-122633500 http://sonylisation.deviantart.com/art/Ruby-Nr-2-207831683
bowling.score.should eq(0)
inrubyeverythingisanobjectandallobjectsareopenbowling.score.should eq(0)
inrubyeverythingisanobjectandallobjectsareopenhttp://www.flickr.com/photos/owenbooth/126288240/bowling.score.should eq(0)
inrubyeverythingisanobjectandallobjectsareopenhttp://www.flickr.com/photos/owenbooth/126288240/bowling.score.should eq(0)
$this->spec($bowling->getScore())->shouldEqual(0);PHPSPECEARLYSYNTAXEXAMPLE
http://www.flickr.com/photos/jamesrbowe/8403688026/amber... red... green...
md@bossa:tests $ phpunit .PHPUnit 3.7.14 by Sebastian Bergmann.PHP Fatal error: Class Customer not foundin /Users/mduarte/...
yougottabemockingme!
public function testUpdateWithEqualTypes(){$installer = $this->createInstallerMock();$manager = new InstallationManager(ve...
@_md@everzet
goals{funtoworkwith
goals{developmenttoolfuntoworkwith
goals{developmenttoollet’snotgetinthewayfuntoworkwith
goals{enforce(mockist)TDDdevelopmenttoollet’snotgetinthewayfuntoworkwith
goals{enforce(mockist)TDDdoitthePHPwaydevelopmenttoollet’snotgetinthewayfuntoworkwith
{"require-dev": {"phpspec/phpspec": "2.0.*@dev"},"config": {"bin-dir": "bin"},"autoload": {"psr-0": {"": "src"}}}
$ bin/phpspec describe Some/Class$ bin/phpspec describe Some/Class
$ bin/phpspec describe Some/Class$ bin/phpspec run$ bin/phpspec describe Some/Class$ bin/phpspec run
$ bin/phpspec describe Some/Class$ bin/phpspec runphpspec generators$ bin/phpspec describe Some/Class$ bin/phpspec runphps...
$ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators$ bin/phpspec describe Some/Class...
$ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators$ bin/phpspec describe Some/Class...
$ bin/phpspec describe Some/Class$ bin/phpspec run$ editor_of_choice . phpspec generators$ bin/phpspec describe Some/Class...
littledemo
emergentdesign
designemergeiterativelydrivenbytests
designis...
designsoftwareis...
designsoftwareistodescribehowwe’resolvingaproblem
calculatecostvarianceforaperiod
calculatecostvarianceforaperiodPeriod
firstlearndesign,thenemergentdesign
“Key in making great and growable systems is todesign how its modules communicate[andnot]whattheirpropertiesandbehaviourss...
messaging
$this->person->getCar()->getEngine()->ignite();
focusonmessagingmakesthecodeflexible
$this->person->startCar();
describinghowobjectsinteracttosolveproblemswhichroles,responsibilitiesandmessagesdesignsoftwareis
bigdesignupfront
IT’SHARDTOCHANGELATER.
WENEEDTOTHINKABOUTTHINGSBEFOREDEVELOPING.
WENEEDTOMAKESUREWEDON’TMISSANYTHING.
THISISJUSTTHEWAYWEDOIT.
relativecostofrepaircosttimeanalysis design code test deploy rework$
yagni
61%oftherequestedfeaturesareactuallydelivered[Standish Group Report 06]
27%ofrequestedfeaturesareactuallyused
5% to 10%areresponsibleforrealisingthebenefitsenvisioned
designforthehighpriorityitemsandmakeiteasytochangelater
describinghowobjectsinteracttosolveproblemswhichroles,responsibilitiesandmessagesinachange-friendlywaydesignsoftwareinagil...
easiersaidthandone?
testcoderefactor
usesimpledesignrulestorefactor1.Alltestsrunandpass2.Removeduplication3.Removeopacity4.Removecomplexity
resultsincode1.Testable2.Modular3.Expressive4.Simple
lackoftestsbreaksinnerquality1.Viscosity2.Immobility,Rigidity,Fragility3.Unreadable4.Complex
simpledesignisgreattodetectsmells
simpledesign1.Alltestsrunandpass2.Removeduplication3.Removeopacity4.Removecomplexitysmells1. Anytestssmells?2.AnyDRYsmells...
TestSmells• Lackoftests• Testsarenotunitary• Setupistoocomplex• Unclearexercise• Morethanoneexpectationinatest• Noexpectat...
DrySmells• Simpleduplication• Logicduplication• Duplicationofconstant• Alternativeclasseswithdifferentinterfaces
OpacitySmells• Namenotfromdomain• Namenotexpressingintent• Featureenvy• Methoddoesmorethanonething• Methodtoolong• Primiti...
ComplexitySmells• Unnecessaryelse• Unnecessaryif• Unnecessaryswitch• Toomanyargumentspassed• InappropriateIntimacy• Workin...
usedesignpatternstorefactor
creational?behavioural?structural?
whatcanhappeninamethod?
returnavaluemodifystateprintsomethingthrowanexceptiondelegate{methods
returnavaluemodifystateprintsomethingthrowanexceptiondelegate{methodsnotthefinalbehaviour
returnavalueprintsomethingthrowanexceptiondelegate{methodsweshouldprobablydelegatethattoo
returnavaluethrowanexceptiondelegate{methods
designdelegationwithmocks
startbydefiningbehaviour
internallydelegatetoanothermethod
Finally• Definenewrole• Extractcollaboratorsusingmocks• Movebehaviourdefinitiontonewcollaboratortest
phpspecemergentdesignsimpledesignandsmellsdesigningcompositionwithmocks
MarcelloDuarteIworkhereIcontributehereItweethere @_md
Thankyou!
QuestionsorComments?wanttolearnmore?bitly.com/inviqa-bdd-training@_md joind.in/8459
Emergent design with phpspec
Emergent design with phpspec
Upcoming SlideShare
Loading in...5
×

Emergent design with phpspec

5,768

Published on

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 what’s more valuable for the customer at all times and re-steer the direction of the product.

Published in: Technology, Business
0 Comments
26 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,768
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
72
Comments
0
Likes
26
Embeds 0
No embeds

No notes for slide

Emergent design with phpspec

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

    Clipping is a handy way to collect important slides you want to go back to later.

×