views:

776

answers:

6
+12  Q: 

SOLID principles

can somebody explain/name me the priciples of SOLID development ?

+7  A: 

try this link for SOLID (and other principles)

http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

Jaime
+10  A: 

I'm a big fan of this very visual explanation.

Mike Two
Like that one ;)
Heiko Hatzfeld
It is funny but full of pork in my opinion.
Phil
+15  A: 

Do you have a question to one speciffic principle?

  • SRP: Single Responsibility - One reason to exist, one reason to change

  • OCP: Open Closed Principle - Open for extension, closed for modification

  • LSP: Liskov Substitution Principle - An object should be semantically replaceable for it's base class/interface

  • ISP: Interface Segregation Principle - Don't force a client to depend on an interface it doesn't need to know about

  • DIP: Dependency Inversion Principle - Depend on abstractions, not concrete detail or implementations

Heiko Hatzfeld
What? No reference to the source? http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod.
S.Lott
Open-Closed Principle comes from Bertrand Meyer.
Nat
LSP is of course named after Barbara Liskov.
quamrana
IMHO the Open-Closed Principle is overused, most classes should simply be closed.
starblue
@starblue: The problem is that most classes are **not** closed to modification. Programmers keep tinkering with them. It would be marvelous if most classes really were closed, **and** open to extension. That would fulfill OCP. More often refactoring means occasional modifications to enable closure to further modifications.
quamrana
I really like this answer. ISP and DIP make more sense to me now.
Phil
+3  A: 

Omu, go with Mike Two's answer. Those are great motivational posters. Some people explain Liskov Substitution Principle with circles and ellipses, squares and rectangles, but you can't put it better than this:

"If it looks like a duck, quacks like a duck, but requires batteries, then you have a wrong abstraction."

azheglov
+6  A: 

Here's some links that speaks more to this and has some samples:

http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

http://www.lostechies.com/blogs/chad%5Fmyers/archive/2008/03/07/pablo-s-topic-of-the-month-march-solid-principles.aspx

http://www.davesquared.net/2009/01/introduction-to-solid-principles-of-oo.html

Paraphrased from links...

S - Single responsibility - This means that a class should only do one thing. A class that does this makes it easier to change and conversly one that doesn't is much harder to maintain.

O - Open for extension, closed to modification - This means you should only change a classes behaviour by using inheritance and/or composition. It also means you should be careful in how you design your classes to be resilent to change in such a way that they won't easily break code relying on it.

L - (LSP) Derived objects should be substituable with the parent and everything should work properly. - This means that when you use a subclass in place of its parent everything should work. This may seem simple but take the classic square derived from a rectangle class and what happens if you have a parent method to set the width. This is different for a rectangle and a square.

I - (Interface segratation) Interfaces should only be forced upon those who use/need them. - Keep your interfaces small and to the point to help ensure this rule. Don't create large interfaces much like creating large classes as they start to break the Single responsibility rule.

D - (Dependency Inversion Principle) Break Dependencies. - Use interfaces instead of types when possible to help break dependencies between classes.

Definitely not the best explanation but I try... :)

klabranche
A: 

These videos created by Stephen Bohlen will help you ... http://www.dimecasts.net/Casts/ByTag/SOLID%20Principle

João Guilherme