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
11. 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;
}
12.
13. 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.
23. 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.
24. 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);
}
}
}
51. 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());
}
}
52. interface CompetencyDictionaryFinder
{
/**
* Gets the dictionary for a particular role
*
* @param LearnerRole $role
* @return InviqaLearningCompetencyDictionary
*/
public function findByLearnerRole(LearnerRole $role);
}
53. /**
* @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()];
}
}
54. 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;
}
}