Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Loading in …3
×
1 of 64

Barely Enough Design

161

Share

Download to read offline

Test Driven Design really helps us learn about the design of our code and how to improve on it. It is also true that the more we know about design, the more our code can actually benefit from TDD. This talk will cover just enough to give you the design inspiration you need to appreciate TDD. We will see responsibility driven design, "Tell don't ask", the law of Demeter, Dependency Inversion and other very key design principles and how they change the way we look into coding and testing

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Barely Enough Design

  1. by@_md Barely Design * Enough
  2. Iworkhere Icontributehere Itweethere @_md MarcelloDuarte
  3. bigdesignmotivators principlesbehindsimplicity responsibility-drivenprocess{
  4. IT’SHARDTOCHANGELATER.
  5. WENEEDTOTHINKABOUTTHINGSBEFOREDEVELOPING.
  6. WENEEDTOMAKESUREWEDON’TMISSANYTHING.
  7. THISISJUSTTHEWAYWEDOIT.
  8. proceduralprogrammersarecomfortable withdata-drivendesign
  9. class SomethingPeopleCallEntity { public function getABitOfThis() { return $this->aBitOfThis; } public function getABitOfThat() { return $this->aBitOfThat; } public function getABitOfTheOtherThing() { return $this->aBitOfTheOtherThing; } public function getSomeOfThis() { return $this->someOfThis; } public function getSomeOfThat() { return $this->someOfThat; } public function getSomeOfTheOtherThing() { return $this->someOfTheOtherThing; }
  10. demeter For all classes C, and for all methods M attached to C, all objects to which M sends a message must be instances of classes
 associated with the following classes: 1.The argument classes of M (including C.) 2.The instance variable classes of C.
  11. $this->person->getCar()->getEngine()->ignite();
  12. leadsustonamingafterstructure
 fragility viscosity disregardtoencapsulation{ data-driven
  13. onlytalktoimmediatefriends demeter
  14. minimisetheinteractionbetweenobjects tell don’t ask
  15. $this->person->startCar();
  16. putthebehaviourwherethedatais tell don’t ask
  17. simplicity
  18. “Getitdoneintenminutesandmoveon.Savethebig sortimplementationforwhenthegoldownersdecide thesystemistooslow. Encapsulationwillsaveyou.” Ron Jeffries simplicity
  19. abstraction |əәbˈstrakʃ(əә)n| noun [ mass noun ] 1 the quality of dealing with ideas rather than events: topics will vary in degrees of abstraction. • [ count noun ] something which exists only as an idea: the question can no longer be treated as an academic abstraction. 2 freedom from full representation in art:geometric abstraction has been a mainstay in her work.
  20. class TestRunner { public function __construct(ProgressFormatter $formatter) { $this->progressFormatter = $formatter; } public function run(Test $test) { try { $test->run(); $this->progressFormatter->markPass(); } catch (Exception $e) { $this->progressFormatter->markFail($e); } } }
  21. “Customersknow! Conferenceroomwithevillittleminds:muahaha!” Uncle Bob change
  22. WENEEDANYANCATFORMATTERNOW!
  23. class NyanCatFormatter extends ProgressFormatter { }
  24. http://mmw-blog.blogspot.co.uk/2010/07/happy-women-joyful-freedom-happiness.html
  25. class TestRunner { public function __construct(Formatter $formatter) { $this->formatter = $formatter; } public function run(Test $test) { try { $test->run(); $this->formatter->markPass(); } catch (Exception $e) { $this->formatter->markFail($e); } } }
  26. class NyanCat implements Formatter { }
  27. abstractrolesthatcanchange
  28. «interface» Formatter + markPass() + markFail() interface=role+responsibilities
  29. messaging
  30. «interface» Formatter + markPass() + markFail() Test Runner + run(:Test) Progress NyanCat …
  31. whendowedecidetoaddanabstraction
  32. "Makethecommitmentatthelast
 responsiblemoment" Preston Smith decide later
  33. designsoyoucancommitlater
  34. fabric
  35. objects values { concepts
  36. identity state behaviour {objects
  37. entitieshaveidentitiesandstate
 whynotusetheminyouOOdesign?
  38. process
  39. “ThefullbenefitofOOcanonlyberealizedif encapsulationismaximisedduringthedesignprocess.
 
 RDDspecifiesobjectbehaviourbeforeobjectstructure andotherimplementationconsiderationsaremade.” Rebecca Wirfs-Brock responsibilities
  40. “Wehavefoundthatthemosteffectivewayofteaching theidiomaticwayofthinkingwithobjectsistoimmerse thelearnerinthe"object-ness"ofthematerial.” Ward Cunningham CRC
  41. identifyscenarios listresponsibilities identifyroles,values dreamtheboundaries { CRC
  42. CRC
  43. Course Students LessonsEnrol students Display outline/info Keep track of vacancies CRC
  44. “Knowinadvancewhereyouaregoingtoputcertain behaviours. […]Inshort,beforeyouwriteyourfirst test,youhavetodreamupthe[boundaries]thatyou wishyouhad.” Uncle Bob boundaries
  45. Dependency Inversion Principle [Martin 02] Behaviour Collaborator Collaborator Role Role
  46. class CompetencyFinder { private $learner; private $finder; public function __construct(Learner $learner, CompetencyDictionaryFinder $finder) { $this->learner = $learner; $this->finder = $finder; } public function findDictionary() { return $this->finder->findByLearnerRole($this->learner->getLearnerRole()); } }
  47. interface CompetencyDictionaryFinder { /** * Gets the dictionary for a particular role * * @param LearnerRole $role * @return InviqaLearningCompetencyDictionary */ public function findByLearnerRole(LearnerRole $role); }
  48. /** * @Route(service="controllers.skills") */ class SkillsController { private $competencyFinder; private $raterFinder; public function __construct(CompetencyFinder $competencyFinder) { $this->competencyFinder = $competencyFinder; } /** * @Route("/skills", name="skills") * @Template() * Show the skill for the learners role */ public function indexAction() { return ['competencies' => $this->competencyFinder->findDictionary()]; } }
  49. class Skill { private $skillChanges; public static function rate($skill, Learner $learner, Rating $rating) { $skillChange = new SkillChangeEvent($skill, $learner, $rating); $skill = new Skill(); $skill->skillChanges[] = $skillChange; } public function getSkillChanges() { return $skill->skillChanges; } }
  50. tdd
  51. usescenariosandexamples tobuildyourdomain
  52. considerinvertingdependencies
 aroundtheboundaries
  53. firstlearndesign thentest-drivendesign
  54. usetherighttoolsfortherightjob
  55. concluding
  56. bigdesignmotivators principlesbehindsimplicity responsibility-drivenprocess learndesignthenTDD{
  57. Iworkhere Icontributehere Itweethere @_md MarcelloDuarte
  58. Thankyou joind.in/13373
  59. Credits http://earthymoon.deviantart.com/art/Elephant-png-122633500 http://mmw-blog.blogspot.co.uk/2010/07/happy-women-joyful- freedom-happiness.html

×