Title: Agile%20Software%20Development
1Agile Software Development
2??
- Introduction
- Agile Development
- Agile Design
3??
- Introduction
- Agile Development
- Agile Design
4Introduction
- Robert C. Martin Agile Software Development
Principles, Patterns, and Practices, Prentice
Hall (October 25, 2002)
Jolt Award 2003
5Introduction
Designing Object Oriented C Applications using
the Booch Method , 1995 Pattern Languages of
Program Design 3, 1997
More C Gems, 1999
Extreme Programming in Practice, 2003 UML for
Java Programmers ,2003
Uncle Bob
http//www.objectmentor.com
6Agile ??
- ??????????????????????????
- ????????????? -- practice
- ??????????????? -- principle
- ??????????? -- pattern
- ??????????,???????
7The Agile Alliance ????
- The Manifesto of the Agile Alliance ??????, 2001
http//www.agilealliance.org/
- We are uncovering better ways of developing
software - by doing it and helping others do it. Through
this work - we have come to value
- Individuals and interactions over processes and
tools - Working software over comprehensive documentation
- Customer collaboration over contract negotiation
- Responding to change over following a plan
Kent Beck, Alistair Cockburn, Robert C. Martin,
etc.
8??????
- ????????????
- ????????????????
- ??????????
- ??????????
9Principles
- ?????????????????????????????????
- ?????????,???????????????????????????
- ?????????????,????????????????,????????????
10Principles
- ?????????,????????????????????
- ?????????????????????????????,?????????????
- ?????,??????????????????,?????????
11Principles
- ????????????????
- ?????????????????????????????????????????????
- ???????????????????????
12Principles
- ?????????????????????
- ???????????????????
- ??????,????????????????????,????????????????
13Agile Processes
- SCRUM
- Crystal
- Feature Driven Development ????????
- Adaptive Software Development ???????
- eXtreme Programming (XP) ????
14??
- Introduction
- Agile Development
- Agile Design
15Agile Development
- Extreme Programming(XP,????) ?????????????,???????
?,????????,????????????????????? - XP??????,????????????????????
- XP??team work??????,??,?????????????,????????????,
???????,???????????????
16Extreme Programming
- XP??4???
- ??(communication),XP???????????????????????
- ??(simplicity),XP????????????
- ??(feedback),????????,?????????????
- ??(courage),??????????????
17Extreme Programming
- XP??????????????,??????????????????,??????????????
- XP????????????,?????????????????,XP????????
- XP???????(???),???2-12???,XP???????????
18Practices of XP
- ????????
- ???? user stories
- ?????
- ????
- ????
- ????
- ???? pair programming
19Practices of XP
- ????????? Test-Driven Development
- ?????
- ????
- ????????
- ???????
- ???? planning game
- ?????
- ?? Refactoring
- ?? Metaphor???????????????
20??
- Introduction
- Agile Development
- Agile Design
21What is Design?
- After reviewing the software development life
cycle as I understood it, I concluded that the
only software documentation that actually seems
to satisfy the criteria of an engineering design
is the source code listings. - -- Jack Reeves
22Design Smells
- Rigidity ??? ? ????
- Fragility ??? ? ????
- Immobility ??? ? ????
- Viscosity ??? ? ????
- Needless Complexity ???????
- Needless Repetition ??????
- Opacity ???
23The Copy Program
void copy() int c while ((cRdKbd())!
EOF) WrtPrt(c)
24Requirement changes
- bool ptFlag false
- //remember to reset this flag
- void Copy()
- int c
- while ((c(ptFlag?RdPt() RdKbd())!EOF)
- WrtPrt(c)
25Requirement changes again!
bool ptFlag false bool punchFlag
false //remember to reset these flags void
Copy() int c while ((c(ptFlag?RdPt()
RdKbd())!EOF) punchFlag ? WrtPunch(c)
WrtPrt(c)
26Agile design of the copy example
- int RdKbd()
- void WrtPrt(int)
- const int EOF -1
- class Reader
- public virtual int read() 0
-
- class KeyboardReader public Reader
- public virtual int read() return RdKbd()
-
- KeyboardReader GdefaultReader
- void Copy(reader reader GdefaultReader)
- int c
- while ((creader.read()) ! EOF)
- WrtPrt(c)
27Agile developers
- Knew what to do because
- Detect the problem by following agile practices
- Diagnose the problem by applying design
principles - Solve the problem by applying the appropriate
design pattern - The interplay between these three aspects of
software development is the act of design.
28A more complex example Multi-panel interactive
systems
- ??
- ????
- ??????
- ???????
- ??
28
29Multi-panel interactive systems
- ??
- ????
- ????(session)???????
- ????
- ??panel(???),??????(??),????,???,????????????????
???(????????????????) - ????
- ??
- ????
29
302019/7/10
Institute of Computer Software Nanjing University
31?????
32????
?????????? (????)????? ?????
33A Simple-minded solution
34A Simple-minded solution
- ??
- Goto!
- ??
- ????????hardwired?????????
- ???????????
- ?????
34
35A functional, top-down solution
- ?,????goto,????????,??????? transition(state,choi
ce)
35
36(No Transcript)
37Top-down decomposition
38The top
39(No Transcript)
40Critique
41(No Transcript)
42Fragileness
???????
???????????
43object-oriented architecture
- Law of inversion
- If your routines exchange too many data, put your
routines in your data.
44State as a class
45(No Transcript)
46Use inheritance and deferred class
47(No Transcript)
48(No Transcript)
49(No Transcript)
50(No Transcript)
51(No Transcript)
52The system? An ADT, not a main function
53(No Transcript)
542019/7/10
Institute of Computer Software Nanjing University
54
55(No Transcript)
56(No Transcript)
57(No Transcript)
58??
- Focus on data abstraction
- Forget the main function of the system,
resist the constant temptation to ask What does
the system do? - Law of inversion
- Realworldliness is not a significant difference
between OO and other approaches what counts is
how we model the world
59??
- Introduction
- Agile Development
- Agile Design
- design principles
60Design Principles
- SRP (The Single-Responsibility Principle) ??????
- OCP (The Open-Closed Principle) ??-????
- LSP (The Liskov Substitution Principle)
Liskov???? - DIP (The Dependency-Inversion Principle) ??????
- ISP (The Interface-Segregation Principle) ??????
61SRP ??????
- A class should have only one reason to change.
??????,??????????????? - What is a Responsibility?
- A reason for change ???????????????????,??????,???
?????????? - An axis of change is an axis of change only if
the changes actually occur. ??????????????????????
?
62Example
??????
????
63Example applying SRP
??????
??????
64Example SRP violation
- interface Modem
- public void dial (String pno)
- public void hangup()
- public void send (char c)
- public char recv()
connection management
data communication
65Example
- Separated modem interface
????????????????????????,?????????!
66OCP ??-????
- Software entities (classes, modules, functions,
etc.) should be open for extension, but closed
for modification. ????(????????)????????,???????? - OCP is the heart of OO design!
67OCP Description
- Two primary attributes
- Open for extension the behavior of the module
can be extended - Closed for modification extending the behavior
of a module does not result in changes to the
source or binary code of the module. - ??????,???
- Is it possible?
68Abstraction is the key!
Client is neither open nor closed
69Strategy Pattern
Client is both open and closed
70Template Method Pattern
A clear separation of generic functionality from
the detailed implementation of that functionality
71Shape????
--------drawAllShape.cc--- typedef struct Shape
ShapePointer void DrawAllShapes(ShapePointer
list, int n) int i for (i0iltni)
struct Shape slisti switch
(s-gtitsType) case square
DrawSquare((struct Square)s) break
case circle DrawSquare((struct Circle)s)
break
--------shape.h---------- enum ShapeTypecircle,sq
uare struct Shape ShapeType
itsType --------circle.h--------- struct
Circle ShapeType itsType double itsRadius
Point itsCenter --------square.h--------- str
uct Square ShapeType itsType double
itsSide Point itsTopLeft
72??OCP
class Shape public virtual void Draw()
const0 class Squarepublic Shape
public virtual void Draw() const class
Circlepublic Shape public virtual void
Draw() const void DrawAllShapes(vectorltShape
gt list) vectorltShapegtiterator I for
(ilist.begin()i!list.end()i)
(i)-gtDraw()
73??100??!
- ???????????????????,???
- ?????????,?????????????!
74Heuristics
- OCP????????????!
- ?????????????
- ??OOPL??????OCP
- ????????????
- 100??????,?????????????
- ????????????????????,??????????????????
75LSP Liskov????
76LSP Liskov????
- Subtypes must be substitutable for their base
types. ????????????????? - If for each object o1 of type S there is an
object o2 of type T such that for all programs P
defined in terms of T, the behavior of P is
unchanged when o1 is substituted for o2 then S is
a subtype of T. Liskov88 ??????S???o1,???????T??
?o2,???????T?????P?,?o1??o2?,??P??????,?S?T?????
77LSP Violation (I)
RTTI(???????)
- struct Shape
- enum ShapeType square, circle itsType
- Shape(ShapeType t)itsType(t)
-
- struct Circle public Shape
- Circle()Shape(circle)
- void Draw() const
-
- struct Square public Shape
- Square()Shape(square)
- void Draw() const
void DrawShape(const Shape s ) if(s.itsType
Shapesquare) static_castltconst
Squaregt(s).draw() else if (s.itsType
Shapecircle) static_castltconst
Circlegt(s).draw()
78LSP Violation (II)
class Rectangle public void
SetWidth(double w) itsWidthw void
SetHeight(double h) itsHeighth
private double itsWidth double
itsHeight
IS-A Relationship
79LSP Violation (II)
- void SquareSetWidth(double w)
- RectangleSetWidth(w)
- RectangleSetHeight(w)
-
- void SquareSetHeight(double w)
- RectangleSetWidth(w)
- RectangleSetHeight(w)
void f (Rectangle r) r.SetWidth(32) //call
RectangleSetWidth
Square Violated!
Square
80LSP Violation (II)
Are Rectangle and Square self-consistent?
class Rectangle public virtual void
SetWidth(double w) itsWidthw virtual void
SetHeight(double h) itsHeighth
private double itsWidth double
itsHeight
Square
void g (Rectangle r) r.SetWidth(5)
r.SetHeight(4) assert(r.Area()20)
True or false?
Violated!
81The real problem
- Validity is not intrinsic! ?????????
- ????????????????????
- IS-A is about Behavior
- Behaviorally, a Square is not a Rectangle.
- Recall DbC principle about inheritance
- Precondition ??Postcondition ??
82The real problem
- RectangleSetWidth(double w)?????
- Postcond (itsWidthw)(itsHeightold.itsHeight
) - ??SquareSetWidth(double w)???????
- ??????????????????
83Heuristics and Conventions
- Violation 1
- Degenerate functions in derivatives ?????????
- Violation 2
- Throwing exceptions from derivatives ?????????
public class Base public void f() /some
code/ Public class Derived extends Base
public void f()
84LSP
- One of the enablers of the OCP?
- LSP??OCP????????????
- It is the substitutability of subtypes that
allows a module, expressed in terms of a base
type, to be extensible without modification.
?????????????????????????????????????
85DIP ??????
- High level modules should not depend on low-level
modules. Both should depend on abstractions.
??????????????,??????????? - Abstractions should not depend on details.
Details should depend on abstractions.
??????????,?????????? - Inversion ??????????
86Laying
- Booch all well structured OO architectures
have clearly defined layers, with each layer
providing some coherent set of services through a
well-defined and controlled interface.
Unfortunate!
87Laying
Hollywood principle dont call us, well call
you. ???????????????????????????
also an inversion of interface ownership
????????,??????????????
88Example
?
Button
Lamp
poll()
turnOn() turnOff()
- public class Button
- private Lamp itsLamp
- public void poll()
- if (/ some condition /)
- itsLamp.turnOn()
-
89Example
Button
ButtonServer
SwitchableDevice
poll()
turnOn() turnOff()
!
Lamp
- public class Button
- private ButtonServer bs
- public void poll()
- if (/ some condition /)
- bs.turnOn()
-
-
90Heuristic
- Depend on abstractions ?????
- ????????????????????????????????
- According to it
- ???????????????????????
- ?????????????
- ??????????????????????????
- ????????????,??String
91DIP
- ???????????????????????
- ?????????????,??????????,???????????
- DIP?????OO???????????????????????????????????????
92ISP ??????
- Clients should not be forced to depend on methods
that they do not use. ?????????????????? - Deals with the disadvantage of fat interfaces
whose interfaces are not cohesive. ???????????????
93Example
common door!
class Timer public void Register
(int timeout, TimeClient client )
- class Door
- public
- virtual void Lock() 0
- virtual void Unlock() 0
- virtual bool IsDoorOpen() 0
class TimerClient public virtual
void TimeOut () 0
How about a timed door?
94Interface Pollution
But not all varieties of Door need timing!
95Separate Interfaces
- Solution 1 adapter ????????
96Separate Interfaces
- class TimedDoor public Door
- public virtual void DoorTimeOut(int
timeoutId) -
- Class DoorTimerAdapter public TimeClient
- pubic
- DoorTimerAdapter(TimedDoor theDoor)
itsTimedDoor(theDoor) - virtual void TimeOut(int timeoutId)
- itsTimedDoor.DoorTimeOut(timeoutId)
- private
- TimedDoor istTimedDoor
97Separate Interfaces
- Solution 2 multiple inheritance
class TimedDoor public Door, public
TimerClient public virtual void TimeOut(int
timeoutId)
98Heuristic
- ????????????????????!
- ???????????????????????
- ?????,???!
99Design Principles
- SRP (The Single-Responsibility Principle) ??????
- OCP (The Open-Closed Principle) ??-????
- LSP (The Liskov Substitution Principle)
Liskov???? - DIP (The Dependency-Inversion Principle) ??????
- ISP (The Interface-Segregation Principle) ??????
100How to design Packages?
- ?????????????????
- ????????????????????
- ??????????(????)????????????(????)?
- ?????????C?Java????????
- ?????,????????????
101?????????
- REP (The Reuse-Release Equivalence
Principle),????????,????????????? - CRP (The Common-Reuse Principle),??????,??????????
??????? - CCP (The Common-Closure Principle),??????,????????
?????????????????
102REP
- ?????????,???????????????-- ????????
- REP??,????????(granule of reuse)???????(granule
of release)???????????????????????? - ??????????????!
- ??????????,??????????????????????????????????????
103CRP
- ????????????????,???????????,?????????????
- ??????????????????
- ??????????????????????
- jar??????
104CCP
- ??????????????????????????????????????,???????????
???,??????????????? - ???SRP,OCP
- ????????????????????????????
105??????????
- ADP (The Acyclic-Dependencies Principle),??????,??
?????????????? - SDP (The Stable-Dependencies Principle),??????,???
????????? - SAP (The Stable-Abstractions Principle),??????,???
??????????????
106ADP
107ADP
- ????????
- ??MyTasks
- ??MyDialogs
108?????
109?????
- ??2 ????????????,????????????
Jitter???
110Heuristic
- ????????????
- ????????????????????
- ?????????????????????????,??,????????????????
111SDP
- ?????????
- ???????,?????????,?????????????????,??,???????????
?
???
??
112?????
- (Ca)???????????????????????????
- (Ce)???????????????????????????
- ????I 0,1
- I0 ???
- I1 ????
- SDP??????I??????????????I???(?I??????????????)
113?????
Pa
Pb
q
r
s
Pc
Pd
t
u
v
Pc Ca3, Ce1, I1/4
114?? vs. ???
???HOW TO?
i1
i1
i0
??????
???SDP
115?? vs. ???
DIP
116SAP
- ????????????????
- ?????????????,????????????????
- ?????????????,???????????????????????
?????????????!
117Remember
- As with all principles, care must be taken not to
overdo it.
118?? (????????)
- ?????????????????
- ??JDK?Collection??????,?????????????????????????