Introduction To Design Patterns

Pattern is a defined, used and tested solution for a know problem. Design patterns is all about re-use. Software design patterns evolved as a subject of study only when object oriented programming started becoming popular. OOPS and design patterns became inseparable.

In OOPS, we should have well defined boundaries for objects. That is every object should have its roles and responsibilities well defined. Then at next level, we should have a clear interaction plan between objects. If you design a OO software with the above principle, then by default you will be following some of the already defined design patterns.

A formal definition for design patterns, “A design pattern addresses a recurring design problem that arises in specific design situations and presents a solution to it” (Buschmann, et. al. 1996)

Java widely uses design patterns in its APIs. It started as early as Java 1.2 in java foundation classes. By then you can see the widespread use of commonly know design patterns in collections framework and IO packages. When I say commonly known design patterns, I mention about the set of 23 design patterns by Gang of Four (GOF). Gamma, Helm, Johnson and Vlissides known as Gang of Four (GOF) published a book “Design Patterns — Elements of Reusable Software” (1995) based on their series of technical meetings. It is one of the best seller in computer science books till date.

In China gang of four means different set of people. Jiang Qing (Mao Zedong’s fourth wife), Zhang Chunqiao, Yao Wenyuan, and Wang Hongwen were very popular leaders of cultural revolution. They almost seized power after Mao Zedong’s death. But they were finally arrested and imprisoned for life.

Our GOF divided the 23 design patterns into three types creational design patterns, structural design patterns and behavioral design patterns.

Creational design patterns can be used to instantiate objects. Instead of instantiating objects directly, depending on scenario either X or Y object can be instantiated. This will give flexibility for instantiation in high complex business logic situations.

Structural design patterns can be used to organize your program into groups. This segregation will provide you clarity and will enable you for easier maintainability.

Behavioral design patterns can be used to define the communication and control flow between objects.

Following this post, I have planned to write a series of article on these design patterns with java source code examples and UML diagrams. Looking forward to your comments.

This Design Patterns tutorial was added on 27/10/2009.

Comments on "Introduction To Design Patterns" Tutorial:

  1. Srikanth Reddy Sanivarapu says:

    Its really a good blog for the people who are looking for java tutorials.
    I suggest all to go thru this.
    And owner, plz give some more elaborated description for all the topics so,no need to go to another site for reading this.

  2. Joe says:

    Thanks Srikanth. I am working on elaborate and detailed tutorials nowadays. Also, I have plans to update already posted tutorials with more details and sample java source code.

  3. Nilesh says:

    Even i like all your elobrated description and all topics is giving depth knowledge .. Please explore also on j2ee tech like springs ..hibernate and also server side like weblogic , websphere

    Regards
    Nilesh

  4. Srikanth S says:

    Hi Joe,

    Nice explanation. Can you please post a topic that covers entire Design Pattern in one stroke. This need not be an elaborate one, but would be useful for those who are new to Design Pattern. Just to understand each in a simpler way. If base is strong, probably we can explore more in days to come.

    Thanks and Regards
    Srikanth S

  5. Joe says:

    Hi Srikanth,

    I am working on posting about all design patterns. But doing everything in one go will be quite difficult. You can surely expect me to cover as much as design patterns quite soon.

    Thanks,
    Joe.

  6. Harish Dewangan says:

    Hey Srikanth,

    When can we expect more on Design pattern ?
    Really waiting for the same.

    Thanks in advance

  7. Sujeet says:

    Nice I appreciate you ..keep posting sir..

  8. Nagender says:

    This blog is useful .And can we expect on more Design patterns?

    Thanks
    nag

  9. Anand says:

    Hi Joe,

    Nice blog.. i really love this.. kindly post more .j2ee tech..like taking a simple project and covering all most, all important topics by pratical means(Don forget to post screen shots of those…).Do the same using a frame work(Struts or Spring).

    Thanks in advance..

  10. Shital says:

    This is really a nice article. You explained the concept in very easy and understandable language. It would be really great if you can give examples of Java API (internally) using design patterns.

    Thanks,
    Shital

  11. […] Pattern 02/05/2011Singleton design pattern is the first design pattern I learned (many years back). In early days when someone asks me, “do you know any design […]

  12. […] 17/05/2011To extend or modify the behaviour of ‘an instance’ at runtime decorator design pattern is used. Inheritance is used to extend the abilities of ‘a class’. Unlike inheritance, […]

  13. Himanshu says:

    It really gud article for beginners easy to understand.

  14. Anonymous says:

    Joe, Good information on design patterns.

  15. android developer says:

    hi,

    i have a question related to java :
    is there a way to create a sdk (exported to a jar file) while having multiple packages and classes in it, so that only a part of its public classes and methods will be available to the programmer who use them?
    maybe a design pattern for it?

    i’ve read about it over the internet, and it seems that this question is very rare . how could people create sdk’s like that ? did they use a special tool, or did they all flatten all of the packages into one package?

  16. Anonymous says:

    Really impressive.
    Can you please explain Business Deligate Design pattern?

  17. jagadeesh says:

    plz eloborate the J2EE technologies like
    structs and hibernates.
    Difference between structs-1 and atructs-2.

  18. Anonymous says:

    I love this article and looking forward for such a great articles from you…

    Your work is greatly appreciated…

    THANK YOU SO MUCH FOR ALL YOU DO…

  19. Meher Sagar says:

    Hi Srikanth, why can’t post about the J2ME as you are sharing the knowledge about Java ..

  20. Meher Sagar says:

    Sorry for giving wrong name JOE..

  21. […] design pattern is one among the other design patterns that promote loose coupling. It emphasizes one more important aspect of design which is […]

  22. […] design pattern can be implemented in two ways. One using the inheritance method and second using the composition […]

  23. […] you might be wondering, why all the fuss about prototye design pattern and do we really need this design pattern? Just ignore, all the big guys requires it. For you, just understand the pattern and sleep over it. […]

  24. LakshmiNarayana says:

    Hi Joe,

    Nice explanation. Can you please post a topic that covers entire Design Pattern in one stroke. Just to understand each in a simpler way. If base is strong, probably we can explore more in days to come.Can you please explain me in detail

    Thanks,
    Lakshman

  25. […] Proxy means ‘in place of’. In attendance roll call, we give proxy for our friends in college right? ‘Representing’ or ‘in place of’ or ‘on behalf of’ are literal meanings of proxy and that directly explains proxy design pattern. It is one of the simplest and straight forward design pattern. […]

  26. Naina says:

    I am looking forward for more articles.
    The way you write and explain things in short is amazing. I checked your blog just yesterday finding ajax tutorial and now m going through other articles as well. Great work.Keep writing.

  27. […] if we are going to create an object for every star then think of it how much memory we will need. Gang of Four (GoF) have given an example of text editors in their book. If we create an object for every character in a […]

  28. Y.Jayaram Reddy says:

    Hi Joe,

    Thank you so much.We are eagerly waiting for you article on Design Patterns(which include Java code and UML diagrams).
    Thanks in Advance.

  29. Joe says:

    @jayaram,

    Many articles are already posted :-)

  30. […] have done well on covering design patterns. Java is like a ocean and every topic fascinates me and love to write on all those. Day by day […]

  31. Rashmit says:

    Joe,

    I too love Java by heart & reading your multiple blogs on Core Java keep me tightly coupled with Java, I appreciate your efforts in popularizing & helping many Java Techies.

    Its really feel good that you’r looking forward to cover up SPRING in your future releases.

    I wish you BEST OF LUCK for all your upcoming blogs. Once again you’r helping so many people by sharing your knowledge, Hv a happy ahead.

  32. golu says:

    i like java

  33. […] to behavioral design patterns. This is the first tutorial in behavioral category of our famous design pattern […]

  34. Gurudas says:

    Hi joe, really nice article, thanks for explaining it in very simple terms. Really easy to understand it. I have one request could you please explain hashcode() from Object and String class?

  35. Anonymous says:

    Thanks this blog is very helpful

  36. Anonymous says:

    good work…. keep it up

  37. vinod says:

    hello sir, i want to know that how we use design pattern in real project envoironment .

  38. Amit Agrawal says:

    Hey,
    Buddy you have done good job for those who wants to do study on especially Design Patterns,faboulas.Go head….

  39. Suresh says:

    Hi joe
    This is Suresh.And i red the some of the article of your’s,Those are very nice and shows some interest for the learners
    if you never mind now i would like to give a small suggession to you that if you add some practical implemtation exmaples for the desingn patterns that will brings effective explaination for the readers

    Thanks and Regards
    Suresh

  40. […] are different ways to instantiate an object and we have seen a lot in our design pattern tutorial series. A simple and direct way is to use the “new” operator and call the constructor […]

  41. Addisu says:

    Hi Joe,
    It is really nice work.
    Most of your papers are really helpful for both begginners and Senior developers(as a refresher)

    I advise you to have a donation link in the blog.

    Some of us may want to express out thanks through donation of $10.

    Thanks for helping me!!

  42. Kasi Gadde says:

    Gr8 Job. Thank You!

  43. Anonymous says:

    Hi Joe,

    I have a doubt how many design patterns are useful to separates presentation logic to business logic.

    Like Mvc, Stratagy,Facade, Service ,singleton ect..

    Thanks,
    Suresh

  44. Ankur says:

    Thanks Joe.. your effort really appreciated..

  45. Monish says:

    good..

Comments are closed for this "Introduction To Design Patterns" tutorial.