<pedrocorreia.net ⁄>
 

<Object Oriented Design Principles ⁄ >




clicks: 262 262 2009-01-27 2009-01-27 goto programacao myNews programacao  Bookmark This Bookmark This


Recently, I was asked which patterns and principles I would use in an OO-project.

As I started summing them up, I noticed the person who asked getting a StackOverflowException :) . Obviously, I had a lot to tell about the subject...
I'll add a description (I'll try to keep it short) to each one of them, but if you don't know the meaning, just read the papers, blogs, or books. I'll link to them (also check the titles, they may be links).

Feel free to add anything I forgot!


Single Responsibility principle (The S in SOLID principles)

This principle states an object should only have one responsibility. Why? So a class only has one reason to change. Why? Because when a class has several responsibilities, they become coupled. So? If you change one responsibility of the class, it could have consequences in the other responsibilities, so you have to retest all responsibilities.
It's a bit confusing in the beginning to recognize a responsibility. Uncle Bob says a responsibility within SRP can be defined as a reason to change. That should get you started!

Open Closed principle (The O in SOLID principles)

The OCP states that software entities, should be open for extension, but closed for modification. What? You should be able to extend a SE without changing it. Why? If you don't change it, you won't break it. You will only have to test what you extended. How? Abstract away the functionality that could be implemented in different ways. If you have calculations, create an interface ICalculation, and add an implementation per calculationtype. The consequence is, that your calculation is closed for modification (a calculation calculates something and that's it) but open for extension (if you have an addition, but also need a substraction, just add a class that implements ICalculation and you're done). This is also a perfect example of the Strategy pattern.



este é só um excerto do artigo, para aceder ao artigo completo, clique no link em baixo:
this is just a small excerpt from the article, to access the full article please click in the link below:

http://www.dotnetkicks.com/other/Object_Oriented_Design_Principles




Subscribe News RSS  Subscribe News Updates by E-mail





myNews <myNews show="rand" cat="programacao" ⁄>

How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization

In an ASP.NET Web page, you can set to two culture values, the Culture and UICul (...)

clicks: 392 392 2009-02-28 2009-02-28 goto url (new window) msdn.microsoft.... goto myNews programacao


Microsoft: .Net Beat Java, Who's Next?

Microsoft is leaving Java in the dust, but the company still has room to grow in (...)

clicks: 575 575 2006-07-31 2006-07-31 goto url (new window) eweek.com/artic... goto myNews programacao


Self-currying JavaScript functions

I'm telling you, this language keeps surprising me. You'll need Prototype for th (...)

clicks: 558 558 2008-02-10 2008-02-10 goto url (new window) blog.jcoglan.co... goto myNews programacao


The Enhanced for loop in Java 1.5 (5.0)

There have been a lot of enhancements to existing features in Java 1.5 (5.0). On (...)

clicks: 578 578 2007-08-10 2007-08-10 goto url (new window) devx.com/tips/T... goto myNews programacao


TRULY Understanding Viewstate

If you read this blog at all, by now you've got to be sick of me talking about V (...)

clicks: 522 522 2006-07-30 2006-07-30 goto url (new window) infinitiesloop.... goto myNews programacao


Quick Tip: JavaScript Event Delegation in 4 Minutes

Event delegation can be a confusing topic for those who are unfamiliar with the (...)

clicks: 48 48 2010-01-30 2010-01-30 goto url (new window) net.tutsplus.co... goto myNews programacao


Writing a Digg-Style Popularity Algorithm

Not so long ago I was tasked with creating a web site similar to Digg - users vo (...)

clicks: 606 606 2007-04-04 2007-04-04 goto url (new window) webcodr.com/4/w... goto myNews programacao


Object Oriented Programming With JavaScript

If you have ever looked at JavaScript as more than just a language for validatio (...)

clicks: 521 521 2008-10-15 2008-10-15 goto url (new window) dev102.com/2008... goto myNews programacao