One
of the roles of the software architect is to act as a mentor/coach. Reviewing
some of the designs in one of my projects' teams it seems the time was ripe for
doing just that. Thus, last week I gave them a presentation on the basics of good OO design - which I thought might also be of interest for other people (you can download a copy
here - 312KB).
The
presentation starts with the 7 deadly
sins of software design:
- Rigidity – make
it hard to change
- Fragility –
make it easy to break
- Immobility –
make it hard to reuse
- Viscosity –
make it hard to do the right thing
- Needless
Complexity – over design
- Needless
Repetition – error prone
- Not doing any
It
is interesting to note that just yesterday I read an interesting piece on what
makes good design (i.e. looking from the positive side) by James Shore (found via Sam Gentile)
The
main part of the presentation demonstrates the 5 basic design principles
(drafted by people like Robert C. Martin , and Barbara Liskov
):
- OCP open-closed
principle - a class should be open for extension but closed for
modifications
- SRP single
responsibility principle - a class should have a single responsibility
- ISP interface
segregation principle - there should be separate interfaces for different
consumer types
- LSP Liskov
substitution principle - basically design by contract - a sub-class should
fulfill the same expectations its suparclass set
- DIP dependency
inversion principle - classes should depends on abstractions, class
consumers should depend on abstractions and abstractions shouldn't depend
on details.
These
principles are the basis for some of the
techniques widely used today - few examples include:
Inversion
Of Control - builds on OCP
Dependency
Injection - a mechanism to allow DIP
Contract
First - building on LSP,DIP
At
the end of the day following these principles helps managing classes
dependencies, increase overall loose coupling and cohesion thus increasing the
overall quality of design. It sometimes amazes me how using just a few simple rules can improve maintainability,
flexibility and usefulness of designs so much.