Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I use OOP programming with inheritance, but I've not yet used interfaces.I want to learn how to use design patterns, but I'm finding them very difficult to learn. Is there is any way to learn design patterns easily?

I searched quite a bit, but I was not able to find useful information.

share|improve this question
    
Apply design pattern in real applications! any doubt? –  Kangkan Mar 1 '11 at 6:00
add comment

migrated from stackoverflow.com Mar 1 '11 at 22:55

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 1 down vote accepted

There is no replacement or short cut to what just Meagar said in one of the earlier post. Following may help but essentially to paraphrase Meagar - the only way to learn swimming is by diving in the water and sink a few times!

Following are some of the links. JUnit Cookbook provides brilliant example of quite a few patterns - really worth checking.

  1. JUnit Cook's Tour
  2. Vince Huton's DP
  3. Design PAtterns

Hope that helps.

share|improve this answer
add comment

Develop software. Until you're writing real software with a real purpose, you won't find a real reason to use any design pattern. You can read and do exercises, but nothing will prepare you the way encountering and solving a real problem will.

Find a problem in your daily workflow and write software to automate it, or do what many people in our field did and write a crummy video game. The only way to learn how to build software well is to build lots of software.

share|improve this answer
1  
+ 1 for essentially mentioning experience. –  Radu Caprescu Mar 1 '11 at 6:27
1  
building software is not the only way to learn how to build software. I agree that it certainly helps, but training in how to use tools of the trade prevents issues with the Law of the instrument. You wouldn't tell a carpenter that they have to build a table using a hammer and hand saw before they can learn to use a power drill and sawbench. –  zzzzBov Mar 1 '11 at 15:52
    
@zzzzBov You missed the point completely. If somebody wanted to learn to build a table using a sawbench, I'd tell them to build a table using a sawbench. Obviously there is going to be some training involved before you start hacking wood apart, but in the end you're going to learn more about building tables from the first crappy table you build than you learned from being trained in how to use the tools. –  meagar Mar 1 '11 at 15:53
1  
@meagar, "Obviously there is going to be some training involved..." that's my point, training is involved before trying to hack together something crummy. @Rahul Mehta is asking for training, and you've said "The only way to learn how to build software well is to build lots of software" which does not help @Rahul learn to use new tools. –  zzzzBov Mar 1 '11 at 16:03
    
@zzzz No, I said the best way is to learn by doing. You're the first one to use the word "only". The question wasn't asking for training - he leads by saying "I use OOP programming with inheritance". We're beyond the training stage here. –  meagar Mar 1 '11 at 16:51
show 3 more comments

you would find various links available on google if you search with "Design patterns".

When I started on design patterns I like this link very much.

http://www.dofactory.com/Patterns/Patterns.aspx

I hope you would also get benefit from this..

share|improve this answer
add comment

A design pattern is just that: A pattern used to design software.

Many clever programmers over the last six decades have discovered themselves writing code for various different projects using the same basic structures.

A simple one is the factory method, instead of writing:

$a = new D();
$a->foo = 'bar';
$a->baz = 'buzz';

$b = new D();
$b->foo = 'bar';
$b->baz = 'buzz';

$c = new D();
...

It is much simpler to have a function that does that all for you:

function makeD()
{
  $temp = new D();
  $temp->foo = 'bar';
  $temp->baz = 'buzz';
  return $temp;
}

and then call it a few times:

$a = makeD();
$b = makeD();
$c = makeD();

This particular pattern is the builder pattern. You can search them on wikipedia, or read about them in a number of books, but don't confuse them for being a panacea.

Design patterns are only patterns, if you find yourself saying "Man, I really could use a simplified way of doing x" then you can probably find a design pattern to simplify the code. Once you've used a few design patterns, they'll start to be part of your toolbox, and you'll be able to look at a problem and tell "I should use an [insert design pattern here]", but if you don't use a formal design pattern, that's ok too.

I would say that interfaces are mostly unrelated to design patterns, although some design patterns use interfaces as part of the pattern.

share|improve this answer
    
AFAIK this is the builder pattern –  Glenner003 Mar 1 '11 at 10:32
    
@Glenner003, why yes it is. –  zzzzBov Mar 1 '11 at 15:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.