SOLID
SOLID
Design
Craig Berntson
www.craigberntson.com
[email protected]
Twitter: @craigber
A little about me
Independent
City
Currently developing database
software for sale to hospitals
Microsoft MVP
INETA Community Speaker
Author
Todays session
Review
Basic OOP
Polymorphism
Encapsulation
Inheritance
Cohesion
Coupling
code
Long method
Large class
Temporary field
Switch statements
Parallel inheritance hierarchies
Design smells
Rigidity
Design smells
Viscosity
complexity
repetition
methodology
Requirements change
Code
wants to be chaotic
suck at OO design
Technical Debt
The
SOLID
Single
Jenga
A real example
A class should
have only one
reason to change
Responsibility
What
a class does
The more a class does, the more
likely it will change
The more a class changes, the
more likely we will introduce bugs
EXAMPLE CODE
Single Responsibility
Principle
Demo
Single
Responsibility Principle
Software entities
(classes, modules,
functions, etc.) should
be open for extension
but closed for
modification
Conforming to OCP
Open
for extension
for modification
Strategy pattern
Conforming to OCP
Rely
on abstractions
Interfaces
Abstract classes
EXAMPLE CODE
Open Closed Principle
Subtypes must
be substitutable
for their base
types
IS-A
Basic
Substitution
Calling
EXAMPLE CODE
Liskov Substitution
Principle
EXAMPLE CODE
Interface Segregation
Principle
EXAMPLE CODE
Dependency Inversion
Principle
Other principles
Keep
Todays session
Review
Questions?
Motivational
posters courtesy of
Derick Bailey through the Creative
Commons License
Contact me
Email: [email protected]
Blog: www.craigberntson.com/blog
Twitter: @craigber