Saturday, February 9, 2013

OOPS Design Principles


What are Software Design Principles?

Software design principles represent a set of guidelines that helps us to avoid having a bad design. The design principles are associated to Robert Martin who gathered them in "Agile Software Development: Principles, Patterns, and Practices". According to Robert Martin there are 3 important characteristics of a bad design that should be avoided:
  • Rigidity - It is hard to change because every change affects too many other parts of the system.
  • Fragility - When you make a change, unexpected parts of the system break.
  • Immobility - It is hard to reuse in another application because it cannot be disentangled from the current application.

Open Close Principle

  • Software entities like classes, modules and functions should be open for extension but closed for modifications.
OPC is a generic principle. You can consider it when writing your classes to make sure that when you need to extend their behavior you don�t have to change the class but to extend it. The same principle can be applied for modules, packages, libraries. If you have a library containing a set of classes there are many reasons for which you�ll prefer to extend it without changing the code that was already written (backward compatibility, regression testing, �). This is why we have to make sure our modules follow Open Closed Principle.
When referring to the classes Open Close Principle can be ensured by use of Abstract Classes and concrete classes for implementing their behavior. This will enforce having Concrete Classes extending Abstract Classes instead of changing them. Some particular cases of this are Template Pattern and Strategy Pattern.

Dependency Inversion Principle

  • High-level modules should not depend on low-level modules. Both should depend on abstractions.
  • Abstractions should not depend on details. Details should depend on abstractions.
Dependency Inversion Principle states that we should decouple high level modules from low level modules, introducing an abstraction layer between the high level classes and low level classes. Further more it inverts the dependency: instead of writing our abstractions based on details, the we should write the details based on abstractions.
Dependency Inversion or Inversion of Control are better know terms referring to the way in which the dependencies are realized. In the classical way when a software module(class, framework, �) need some other module, it initializes and holds a direct reference to it. This will make the 2 modules tight coupled. In order to decouple them the first module will provide a hook(a property, parameter, �) and an external module controlling the dependencies will inject the reference to the second one.
By applying the Dependency Inversion the modules can be easily changed by other modules just changing the dependency module. Factories and Abstract Factories can be used as dependency frameworks, but there are specialized frameworks for that, known as Inversion of Control Container.

Interface Segregation Principle

  • Clients should not be forced to depend upon interfaces that they don't use.
This principle teaches us to take care how we write our interfaces. When we write our interfaces we should take care to add only methods that should be there. If we add methods that should not be there the classes implementing the interface will have to implement those methods as well. For example if we create an interface called Worker and add a method lunch break, all the workers will have to implement it. What if the worker is a robot?
As a conclusion Interfaces containing methods that are not specific to it are called polluted or fat interfaces. We should avoid them.

Single Responsibility Principle

  • A class should have only one reason to change.
In this context a responsibility is considered to be one reason to change. This principle states that if we have 2 reasons to change for a class, we have to split the functionality in two classes. Each class will handle only one responsibility and on future if we need to make one change we are going to make it in the class which handle it. When we need to make a change in a class having more responsibilities the change might affect the other functionality of the classes.
Single Responsibility Principle was introduced Tom DeMarco in his book Structured Analysis and Systems Specification, 1979. Robert Martin reinterpreted the concept and defined the responsibility as a reason to change.

Liskov's Substitution Principle

  • Derived types must be completely substitutable for their base types.
This principle is just an extension of the Open Close Principle in terms of behavior meaning that we must make sure that new derived classes are extending the base classes without changing their behavior. The new derived classes should be able to replace the base classes without any change in the code.
Liskov's Substitution Principle was introduced by Barbara Liskov in a 1987 Conference on Object Oriented Programming Systems Languages and Applications, in Data abstraction and hierarchy

39 comments:

Anonymous said...

Appreciating the dedication you put into your website and detailed information you offer.
It's awesome to come across a blog every once in a while that isn't
the same unwanted rehashed information. Wonderful read!

I've bookmarked your site and I'm adding your RSS feeds to my Google account.


Here is my web blog: background checks Gauteng pre employment vetting Gauteng

Anonymous said...

Hey there! I've been following your blog for some time now and finally got the bravery to go ahead and give you a shout out from Lubbock Tx! Just wanted to tell you keep up the good job!

Also visit my blog post :: radio controlled guards Pietermaritzburg

Anonymous said...

WOW just what I was searching for. Came here by searching for
lost social security card ny

Also visit my webpage ... construction plumbing Gauteng

Anonymous said...

Hi, just wanted to say, I liked this blog post. It was practical.
Keep on posting!

Here is my site :: irrigation Bedfordview

Anonymous said...

I absolutely love your blog and find most of your post's to be exactly what I'm looking for.
Would you offer guest writers to write content in your case?
I wouldn't mind publishing a post or elaborating on most of the subjects you write with regards to here. Again, awesome blog!

Here is my web blog - kids party packs Johannesburg

Anonymous said...

Hello, just wanted to mention, I enjoyed this post.
It was funny. Keep on posting!

My blog post document imaging

Anonymous said...

Hi there! I could have sworn I've visited this site before but after looking at some of the posts I realized it's new
to me. Anyways, I'm definitely pleased I found it and I'll be book-marking it and checking back
regularly!

my webpage :: garage equipment supplier

Anonymous said...

Write more, thats all I have to say. Literally, it
seems as though you relied on the video to make your point.
You obviously know what youre talking about, why throw away your intelligence on just
posting videos to your site when you could be giving us something enlightening to read?


my homepage :: signage Bloemfontein

Anonymous said...

That is really interesting, You are an excessively professional blogger.
I've joined your rss feed and sit up for seeking extra of your great post. Also, I've shared your website in my social
networks

Feel free to surf to my webpage jewellery

Anonymous said...

Highly energetic post, I enjoyed that bit. Will there be
a part 2?

Feel free to surf to my weblog ... book of rah kostenlos spielen

Anonymous said...

Usually I do not read article on blogs, however I wish to say that this
write-up very pressured me to check out and do so!

Your writing style has been surprised me. Thanks, very nice article.


Feel free to visit my web page - novoline app apk

Anonymous said...

It's really very complex in this full of activity life to listen news on Television, therefore I only use internet for that reason, and take the most up-to-date information.

My webpage; books of ra online spielen

Anonymous said...

I'm not sure exactly why but this website is loading extremely slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later
and see if the problem still exists.

Feel free to surf to my web blog: This Web page

Anonymous said...

Hi, i think that i noticed you visited my blog so i got here to return the desire?
.I'm attempting to find issues to improve my web site!I suppose its adequate to use a few of your ideas!!

Here is my blog post: book of rah online

Anonymous said...

Howdy just wanted to give you a quick heads up.

The words in your post seem to be running off
the screen in Internet explorer. I'm not sure if this is a formatting issue or something to do with web browser compatibility but I thought I'd post to let you know.
The design look great though! Hope you get the issue fixed soon.
Many thanks

Also visit my webpage Power Preciision

Anonymous said...

Hi there to all, how is all, I think every one is getting more from this site,
and your views are good for new viewers.

Feel free to visit my web-site ... home articles

Anonymous said...

Hi everybody, here every person is sharing such
familiarity, thus it's fastidious to read this web site, and I used to visit this blog every day.

Also visit my weblog - news release - -

Anonymous said...

You should be a part of a contest for one of the highest
quality websites on the net. I most certainly will highly recommend this website!


Also visit my webpage: government articles

Anonymous said...

Amazing blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple tweeks would
really make my blog stand out. Please let me know where you got your design.
Thanks

Also visit my site :: business finance news

Anonymous said...

Hello to all, it's truly a good for me to pay a visit this web site, it consists of helpful Information.

my blog post - fashion hair

Anonymous said...

Hello, the whole thing is going well here and ofcourse every one is sharing facts, that's really excellent, keep up writing.

Also visit my webpage - Education news

Anonymous said...

I leave a leave a response whenever I especially enjoy a article
on a site or I have something to add to the conversation.
It's caused by the passion displayed in the post I browsed. And on this post "OOPS Design Principles". I was moved enough to drop a commenta response ;-) I actually do have 2 questions for you if it's okay.
Is it only me or do a few of the responses appear like
left by brain dead visitors? :-P And, if you are writing at additional social sites, I'd like to keep up with anything new you have to post. Could you make a list all of your social pages like your twitter feed, Facebook page or linkedin profile?

Look into my blog post Home & Family

Anonymous said...

What's up friends, how is everything, and what you desire to say regarding this piece of writing, in my view its really amazing in support of me.

my web site - government

Anonymous said...

Do you have a spam problem on this site; I also am a
blogger, and I was wanting to know your situation; we
have developed some nice practices and we are looking
to trade techniques with others, please shoot me
an email if interested.

my web site; News Real Estate

Anonymous said...

Asking questions are really fastidious thing if you
are not understanding anything fully, however this
paragraph presents pleasant understanding even.


Here is my site :: What Is Direct Marketing

Anonymous said...

My spouse and I absolutely love your blog and find most of your post's to be what precisely I'm looking for.
Do you offer guest writers to write content in your case?

I wouldn't mind producing a post or elaborating on some of the subjects you write with regards to here. Again, awesome web log!

Stop by my site - public relation

Anonymous said...

Please let me know if you're looking for a author for your blog. You have some really great posts and I feel I would be a good asset. If you ever want to take some of the load off, I'd love to write some material for your blog
in exchange for a link back to mine. Please send me an email if
interested. Many thanks!

Feel free to surf to my website home news *http://www.sykose.net/index.php?do=/profile-3438/info/*

Anonymous said...

Very often it’s hard to get that "perfect balance" between functionality
and visual appearance. I must say that you’ve done a fantastic
job with this particular. Additionally , the blog loads super quick for
me personally on Safari.

Feel free to visit my homepage

Anonymous said...

Sweet blog! I found it while searching on Yahoo News. Do you have any tips on
how to get listed in Yahoo News? I've been trying for a while but I never seem to get there! Many thanks

Feel free to surf to my web blog - public relations ()

Anonymous said...

First off I would like to say terrific blog! I had
a quick question in which I'd like to ask if you do not mind. I was interested to find out how you center yourself and clear your head prior to writing. I have had a tough time clearing my mind in getting my ideas out. I truly do take pleasure in writing however it just seems like the first 10 to 15 minutes are generally wasted simply just trying to figure out how to begin. Any recommendations or tips? Thank you!

Here is my weblog; communication news

Anonymous said...

Undeniably consider that which you said. Your favorite justification appeared to
be on the web the easiest thing to be mindful of.
I say to you, I certainly get annoyed at the same time as other people think about concerns that they just
don't recognize about. You controlled to hit the nail upon the highest as well as defined out the whole thing with no need side-effects , folks could take a signal. Will probably be again to get more. Thanks

Also visit my web-site automotive news

Anonymous said...

I know this if off topic but I’m looking into starting my own web
log and was wondering what all is required to get put up?

I’m assuming having a web log like yours would cost a pretty penny?
I’m not very web savvy so I’m not 100% positive.
Any guidelines or advice could be greatly
appreciated. Relish it

Here is my weblog travel article ()

Anonymous said...

I go to see day-to-day some blogs and information sites to read posts,
however this webpage presents quality based content.

Visit my webpage - home news

Anonymous said...

We are a group of volunteers and opening a new scheme in our community.

Your web site provided us with valuable information to work on.
You have done an impressive job and our entire community will be thankful to you.


Review my blog post ... articles game []

Anonymous said...

Aw, this was a very good post. Taking the time and actual effort to make a good article… but what can I say…
I procrastinate a whole lot and don't manage to get nearly anything done.

Feel free to surf to my webpage - real estate article ()

Anonymous said...

My last weblog (wordpress) was hacked and I wound up losing months of effort due to no backup.
Do you have any methods to stop hackers?

my blog :: energy articles [www.campusjoints.com]

Anonymous said...

I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to
do it for you? Plz reply as I'm looking to construct my own blog and would like to know where u got this from. cheers

Look at my blog post ... restaurants news

Anonymous said...

Hello just desired to offer you a quick heads up. The text in your post
seem to be running off the screen in Opera. I’m uncertain if it is a
format issue or something related to internet browser compatibility but I thought I’d post
to inform you. The look look great though!
Hope you receive the problem fixed soon. Thanks

my web page :: electrical power

Anonymous said...

Do you mind if I quote a few your posts so long as I provide credit and sources back again to
your website? My website is in the same market
as yours and my users would truly reap the benefits of a few of the information you present here.

Please i would ike to know if this okay with you.
Thanks a whole lot!

Visit my site; entertainment news