solid principles
DESCRIPTION
Slides from presentation at agiledays09.TRANSCRIPT
Why it is Agile?
?
principles != rules
Single Responsibility
Principle
Problem domain
Conceptual model
Implementation
Problem domain
Conceptual model
Implementation
?
?
NOooo!!
Book
InstrumentPositionvalue: double
1
*1 1
Book PositionListener 1
BookPosNode
Book PositionListener 2
NetworkApplication
position
position
position
BookPosNode
AbstractBookPosNode
Subscriber
SnapshotProvider
HeartbeatMonitor
StateMachine
1
2
3
4
the rest of the class is collapsed
5
the rest of the class is collapsed
Open/Closed Principle
AbstractPositionNode
BookPosNode
Client
AbstractPositionNode
BookPosNode JMSNode
Client PositionWatcher
Add
Change
AbstractPositionNode
BookPosNode JMSNode
Client PositionWatcher
Add
NodeV2
Front-end
Back-end
Database
Change
Liskov Substitution Principle
Ellipse-circle problem
rectangle-square
Point
x, y : int
#equals()#hashCode()
Point
x, y : int
#equals()#hashCode()
ColorPoint
color : Color
#equals()#hashCode()
Point
x, y : int
#equals()#hashCode()
ColorPoint
color : Color
#equals()#hashCode()
Can't extend like this preserving equals contract
(Effective Java, Item 8)
@IViolateLSP
class Dog implements ICanBark …
class Button implements IClickable …
Interface Segregation Principle
<<interface>>
BigService
Client1 Client2 Client3
<<interface>>
BigService
<<interface>>
Service1<<interface>>
Service2<<interface>>
Service3
Client1 Client2 Client3
BookPositionNode
<<interface>>
ResubscribingNode AbsPosNode
StateMachine
Client
uses
uses
Dependency Inversion Principle
Client
Service
client
service
Client
<<interface>>
ServiceServiceImpl
client
service
client
service
Client
<<interface>>
ServiceServiceImpl
client
service
Client<<interface>>
Service
ServiceImpl
client
service
client
service
Client<<interface>>
Service
ServiceImpl
client
service
api
SRP
OCP
LSP
ISP
DIP
Single Responsibility
Principle
Open/Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
What else?
Problem domain
Conceptual model
Implementation
F**k Design
Zen Coding
and only then for computers
Code is written for
people
REP
CRP
CCP
ADP
SDP
SAP
UML,
patterns,
and more...
Thanks!
SRP
OCP
LSP
ISP
DIP
http://weblogs.java.net/blog/82/2003/09/02/aristotles-error-or-agile-smagile
http://blog.objectmentor.com/articles/2009/01/31/quality-doesnt-matter-that-much-jeff-and-joel
http://www.codinghorror.com/blog/archives/000805.htmlhttp://www.youtube.com/watch?v=2k1uOqRb0HU
http://blogs.msdn.com/brada/archive/2003/10/02/50420.aspx
http://www.joelonsoftware.com/articles/LeakyAbstractions.html
http://www.joelonsoftware.com/items/2009/09/23.html