by@_md
Barely
Design
*
Enough
Iworkhere
Icontributehere
Itweethere @_md
MarcelloDuarte
bigdesignmotivators
principlesbehindsimplicity
responsibility-drivenprocess{
IT’SHARDTOCHANGELATER.
WENEEDTOTHINKABOUTTHINGSBEFOREDEVELOPING.
WENEEDTOMAKESUREWEDON’TMISSANYTHING.
THISISJUSTTHEWAYWEDOIT.
proceduralprogrammersarecomfortable
withdata-drivendesign
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;
}
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.
$this->person->getCar()->getEngine()->ignite();
leadsustonamingafterstructure

fragility
viscosity
disregardtoencapsulation{
data-driven
onlytalktoimmediatefriends
demeter
minimisetheinteractionbetweenobjects
tell don’t ask
$this->person->startCar();
putthebehaviourwherethedatais
tell don’t ask
simplicity
“Getitdoneintenminutesandmoveon.Savethebig
sortimplementationforwhenthegoldownersdecide
thesystemistooslow.
Encapsulationwillsaveyou.”
Ron Jeffries
simplicity
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.
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);
}
}
}
“Customersknow!
Conferenceroomwithevillittleminds:muahaha!”
Uncle Bob
change
WENEEDANYANCATFORMATTERNOW!
class NyanCatFormatter extends ProgressFormatter
{
}
http://mmw-blog.blogspot.co.uk/2010/07/happy-women-joyful-freedom-happiness.html
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);
}
}
}
class NyanCat implements Formatter
{
}
abstractrolesthatcanchange
«interface»
Formatter
+ markPass()
+ markFail()
interface=role+responsibilities
messaging
«interface»
Formatter
+ markPass()
+ markFail()
Test Runner
+ run(:Test)
Progress NyanCat
…
whendowedecidetoaddanabstraction
"Makethecommitmentatthelast

responsiblemoment"
Preston Smith
decide later
designsoyoucancommitlater
fabric
objects
values
{
concepts
identity
state
behaviour
{objects
entitieshaveidentitiesandstate

whynotusetheminyouOOdesign?
process
“ThefullbenefitofOOcanonlyberealizedif
encapsulationismaximisedduringthedesignprocess.



RDDspecifiesobjectbehaviourbeforeobjectstructure
andotherimplementationconsiderationsaremade.”
Rebecca Wirfs-Brock
responsibilities
“Wehavefoundthatthemosteffectivewayofteaching
theidiomaticwayofthinkingwithobjectsistoimmerse
thelearnerinthe"object-ness"ofthematerial.”
Ward Cunningham
CRC
identifyscenarios
listresponsibilities
identifyroles,values
dreamtheboundaries
{ CRC
CRC
Course
Students
LessonsEnrol students
Display outline/info
Keep track of
vacancies
CRC
“Knowinadvancewhereyouaregoingtoputcertain
behaviours. […]Inshort,beforeyouwriteyourfirst
test,youhavetodreamupthe[boundaries]thatyou
wishyouhad.”
Uncle Bob
boundaries
Dependency
Inversion
Principle
[Martin 02]
Behaviour
Collaborator
Collaborator
Role
Role
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());
}
}
interface CompetencyDictionaryFinder
{
/**
* Gets the dictionary for a particular role
*
* @param LearnerRole $role
* @return InviqaLearningCompetencyDictionary
*/
public function findByLearnerRole(LearnerRole $role);
}
/**
* @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()];
}
}
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;
}
}
tdd
usescenariosandexamples
tobuildyourdomain
considerinvertingdependencies

aroundtheboundaries
firstlearndesign
thentest-drivendesign
usetherighttoolsfortherightjob
concluding
bigdesignmotivators
principlesbehindsimplicity
responsibility-drivenprocess
learndesignthenTDD{
Iworkhere
Icontributehere
Itweethere @_md
MarcelloDuarte
Thankyou
joind.in/13373
Credits
http://earthymoon.deviantart.com/art/Elephant-png-122633500
http://mmw-blog.blogspot.co.uk/2010/07/happy-women-joyful-
freedom-happiness.html

Barely Enough Design