De sign Stor ie s
E xplor ing and Cr e ating Code fr
- m a
Nar r ative Pe r spe c tive
Ke vlin He nne y
ke vlin@c ur br alan.c om @Ke vlinHe nne y
De sign Stor ie s E xplor ing and Cr e ating Code fr om a Nar - - PowerPoint PPT Presentation
De sign Stor ie s E xplor ing and Cr e ating Code fr om a Nar r ative Pe r spe c tive Ke vlin He nne y ke vlin@c ur br alan.c om @Ke vlinHe nne y See http://programmer.97things.oreilly.com (also http://tinyurl.com/97tepsk ) and
E xplor ing and Cr e ating Code fr
Nar r ative Pe r spe c tive
ke vlin@c ur br alan.c om @Ke vlinHe nne y
See http://programmer.97things.oreilly.com (also http://tinyurl.com/97tepsk) and follow @97TEPSK
stablish a c le ar vision of the whole
stor ie s, use c ase s,
sc e nar io style s, fe atur e s, spike s, pr
amming e pisode s, e tc .
e sponsive and r e ac tive
quaff, v.
To drink deeply; to take a long draught; also, to drink repeatedly in this manner.
quaff, n.
An act of quaffing, or the liquor quaffed; a deep draught.
Oxford English Dictionary
.g., a static vie w of c ode str uc tur e
c apabilitie s base d ar
r
stor ie s to patte r n stor ie s
same time or in the same plac e as value or
me asur e s of pr ior ity
.g., use c ase s, use r stor ie s, use r stor y maps, F DD fe atur e s and othe r sc e nar io- base d te c hnique s — e mphasis in e ac h c ase is diffe r e nt, but all ar e r e late d
he y c an be applie d r e c ur sive ly
"Vin on Point", Joseph D Carney
The new user story backlog is a map Jeff Patton
http://www.agileproductdesign.com/blog/the_new_backlog.html
e quir e me nts impose d
e sts should de fine be haviour , not just pr
testIsLeapYear testNonLeapYears testLeapYears yearsNotDivisibleBy4AreNotLeapYears yearsDivisibleBy4ButNotBy100AreLeapYears yearsDivisibleBy100ButNotBy400AreNotLeapYears yearsDivisibleBy400AreLeapYears
Procedural test structured in terms of the function being tested, but not in terms
Tests partitioned in terms of the result of the function being tested: Propositional tests reflecting requirements and partitioned in terms of the problem domain (prefix with test_that if test is required as a prefix):
public static boolean isLeapYear(int year) years_not_divisible_by_4_are_not_leap_years years_divisible_by_4_but_not_by_100_are_leap_years years_divisible_by_100_but_not_by_400_are_not_leap_years years_divisible_by_400_are_leap_years
Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. Refactor (verb): to restructure software by applying a series of refactorings without changing the observable behavior of the software.
Martin Fowler, Refactoring
Functional Operational Developmental
class access_control { public: bool is_locked(const std::basic_string<char> &key) const { std::list<std::basic_string<char> >::const_iterator found = std::find(locked.begin(), locked.end(), key); return found != locked.end(); } bool lock(const std::basic_string<char> &key) { std::list<std::basic_string<char> >::iterator found = std::find(locked.begin(), locked.end(), key); if(found == locked.end()) { locked.insert(locked.end(), key); return true; } return false; } bool unlock(const std::basic_string<char> &key) { std::list<std::basic_string<char> >::iterator found = std::find(locked.begin(), locked.end(), key); if(found != locked.end()) { locked.erase(found); return true; } return false; } ... private: std::list<std::basic_string<char> > locked; ... };
class access_control { public: bool is_locked(const std::string &key) const { return std::count(locked.begin(), locked.end(), key) != 0; } bool lock(const std::string &key) { if(is_locked(key)) { return false; } else { locked.push_back(key); return true; } } bool unlock(const std::string &key) { const std::size_t old_size = locked.size(); locked.remove(key); return locked.size() != old_size; } ... private: std::list<std::string> locked; ... };
class access_control { public: bool is_locked(const std::string &key) const { return locked.count(key) != 0; } bool lock(const std::string &key) { return locked.insert(key).second; } bool unlock(const std::string &key) { return locked.erase(key); } ... private: std::set<std::string> locked; ... };
Confronted with two options, most people think that the most important thing to do is make a choice between them. In design (software or otherwise) it is not. The presence of two options is an indicator that you need to consider uncertainty in the design. Use the uncertainty as a driver to determine where you can defer commitment to details and where you can partition and abstract to reduce the significance of design decisions. Kevlin Henney "Use Uncertainty as a Driver"
e xplic it, c onsc ious or not
he naming of a patte r n c ontr ibute s to de sign voc abular y
ns de sc r ibe d in te r ms of c onte xt, pr
c e s, solution str uc tur e and c onse que nc e s
Terminal Expression
evaluate
Expression
evaluate
NonTerminal Expression
evaluate
*
Composite: Composite Composite: Leaf Composite: Component Command: ConcreteCommand Command: ConcreteCommand Command: Command
Client Context
Context Object: ContextObject Composite: Client Command: Client Context Object: Owner Context Object: Client
*
1
TestSuite TestResult
«interface»
TestListener
«interface»
Test run
«role»
TestRunner
*
1
TestCase run setUp tearDown
Command Processor Command Observer Composite Double Dispatch Collecting Parameter Template Method
e c onc e ptual nar r ative be hind a give n pie c e of de sign, whe the r a syste m in pr
an illustr ative e xample
c e s and c onse que nc e s playe d out in or de r , e ac h de c ision illustr ate d c onc r e te ly
James Burke
ibe d and applie d inde pe nde nt of a patte r n stor y
n se que nc e s foc us on inc r e me ntal de ve lopme nt
.g., MVC, Pluggable F ac tor y
e c ur r ing se t of ove r lapping and inte r ac ting r
Composite 〉
e mplate Me thod, Colle c ting Par ame te r , Class Adapte r , Pluggable Se le c tor , Composite 〉
.g., what c lasse s play what r
Composite
e s c onne c tions and possibilitie s be twe e n patte r ns, inc luding options, alte r native s and ne c e ssar y ste ps
n se que nc e c an be c onside r e d a nar r
n language
VAL
UE
O BJE
CT
I
MMUT ABL E
VAL
UE
COPIE
D
VAL
UE
MUT
ABL E
COMPANION CL
ONING
COPY CONST
RUCT OR
CL
ASS
F
ACT ORY
ME
T HOD
CONVE
RSION
ME
T HOD
O VE
RL OAD–
O VE
RRIDE
ME
T HOD PAIR
BRIDGE ME
T HOD
T
YPE- SPE CIF IC
O VE
RL OAD
CE
L L
VAL
UE
VAL
IDAT ING
CONST
RUCT OR
I
MPL ICIT
F
AMIL IAL
CONVE
RSION
O PE
RAT ORS F OL L OW
BUIL
T
James Siddle "Choose Your Own Architecture" – Interactive Pattern Storytelling
Alice Childress