Click here to Skip to main content
15,936,850 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I know there are three different design patterns in java. 1) Creational 2) Structioral and 3) Behavioral.

Which is the best pattern? How can we select a pattern to design a project? Is it possible to choose more than one patterns in a single project design...if yes how can we?

Thanks in advance
Updated 7-Jul-11 1:34am
Sergey Alexandrovich Kryukov 7-Jul-11 3:29am    
No, you don't know. You don't have any idea, actually, worse than that. Every statement and question here makes no sense at all. This post is beyond any discussion, sorry.

OK, you are obviously new to this topic. I want to second much of what has been said in the answers here.

I know there are three different design patterns in java. 1) Creational 2) Structioral and 3) Behavioral.
First off, the "patterns" you describe aren't patterns at all, they are categories if patterns. Each has numerous patterns within them. You can't compare them to say "which is best", but you can form an opinion about "which is best for my task".

How we can we select a pattern to design a project?
Generally you don't: you apply development patterns (such as you descibed) to features within code. You might want to apply an architectural pattern to a project, but you shouldn't start with the idea "I want to use pattern X to write this project", what you should think is "My project needs to so this, so architectural pattern X is a good idea". The same is true of all pattern types, the needs should dictate the pattern, your shouldn't start with the pattern and force it into your needs.

Is it possible to choose more than one pattern in a single project design.
Absolutely. You apply each pattern as needed, it is even possible to hybridise patterns.

Finally I'd like to say this. Design patterns fulfill two primary functions:

  1. They provide a common nomenclature as a shorthand for a design idea to allow developers to communicate, e.g. I could say "I think this data access stuff would be best wrapped up in a proxy [patter]"
  2. They provide well-understood solutions to common problems

As Christian said, they aren't a magic bullet and they won't suddenly improve your code. Knowing them provides a short-cut to providing a solution to a particular problem so they are worth looking at. If you have done any amount of serious coding you have probably implemented something close to a recognised pattern already. My advice is to find an easy-to-read article on a few basic patterns and implment them yourself.
Share this answer
Silju MC 7-Jul-11 7:34am    
Great... Thanks a lot...
:-) Cheers. My 5+
They aren't design patterns, they are different families of design patterns, for instance, here[^] here you may find a rather huge list of behavioural patterns.
Since different patterns address different problems, there isn't, generally speaking, a 'best pattern' while each patterns should be the 'best solution' to the problem it addresses (it is a duty of the software designer to choose the more appropriate patterns for his application).

Since it is a rather big topic, I suggest you reading a good book (for instance the Gang of Four's[^] one).
Share this answer
Keith Barrow 7-Jul-11 4:51am    
Got my 5.
Silju MC 7-Jul-11 5:15am    
Thanks. My 5 too
Sergey Alexandrovich Kryukov 7-Jul-11 5:23am    
Of course, my 5.
Nagy Vilmos 7-Jul-11 9:40am    
Gets my tick
In addition to what Cristian says, I would like to bring to everyone's attention that there is a reasonable criticism of the whole idea design patterns which I partially agree with, see[^].

Share this answer
Silju MC 7-Jul-11 4:43am    
cheers! 5+
Sergey Alexandrovich Kryukov 7-Jul-11 5:22am    
Thank you for for accepting this answer but you did not actually vote. :-)
Silju MC 7-Jul-11 5:49am    
Sorry... here is my 5. :-)
And I know my question is very poor...
I'm new to designing... so I just want to understand what is design patterns... Google too helps me a lot. Now I got some idea about these patterns. That's fine. Thanks for your Information and comments. :-) :-)
What you 'know' is wrong. There's lots of design patterns, and they are not related to a specific languages. There's all sorts of ways to define patterns, but the classic is the GoF book. I notice that people in India/China/etc have been jumping on the idea of design patterns as a magic bullet. A design pattern will not make your code magically better. It won't magically solve your problems. Design patterns are about knowing different ways to solve problems, and then knowing enough to choose the best one for the task at hand. Even then, you need to implement that pattern well and write good code, or the pattern will not help at all.
Share this answer
Silju MC 7-Jul-11 3:31am    
:-) Nice answer. Thanks. 5+
Sergey Alexandrovich Kryukov 7-Jul-11 3:35am    
Agree, my 5. Not sure about your characteristic of the regional/cultural deceases of people; probably the real picture is more complex. Also, I added an important note in my answer.
Keith Barrow 7-Jul-11 4:51am    
Excellent answer. Design patterns have been a bit of a buzzword in the west for a few years. This has now seemingly hit India and China if several questions I have seen here are a guide.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900