Monday 24 October 2011

Simple understanding of Design Pattern

Reason for writing this blog about Design Pattern is that it has been Greek, Latin and Hebrew for me  long time. I figured out, from some of my friends that you need to know about Design Patterns if u want to excel in Technical career. I told my self OK, am gonna figure out this myself. So i downloaded a 400 pages PDF book about Design patterns and read the whole book.

     I felt only one thing. this is really Greek and Latin.

   Actually i heard the word for the first time about design pattern from my client's architect Doi San, when i was working for a project in Japan. He said we use combined Data factory and Singleton pattern in this project. I could relate to Singleton pattern from the project, because the logged in details about the user, will be fetched from database for the first time, when the user logs in and the user object is created and saved.

 Later if we need the user details, the object will not be instantiated, it will send the object that was already created and saved, that way, the database call is only once.

   I could not understand what is Data Factory pattern for a long time even though i implemented almost 5 modules in the project throughout my 6 months tenure in Osaka. I will explain about this later, about this pattern.

  Then I tried using wikipedia to learn it in a layman's term, but no use. Every resource i referred gave me the same definition. So I went back to 400 Page PDF book.

I read the first chapter at least five time to figure out what exactly it means, once i figured out the definition by myself. It became a cake walk for me.

 So I thought, i have figured it out, why not represent in a way that will be simple & easy for others to learn, so they don't have to go through the pain i went through.

 So i have put up this blog which will be useful for others. Stick with me in reading this. You can take these below as guidelines and remember these and you can master it from there. Because first step is always the tough step.

My read of design pattern is
" Design Pattern is set of solutions available for set of problems ".

 The Gang of Four (GOF) patterns are generally considered the foundation for all other patterns. . We will discuss only  about two principles which i feel very important.
  • High Cohesion (Cohesion  meaning Relationship between methods in a class)
  • Low Coupling  (Coupling meaning Dependency between two or more classes)
Remember the above two(also the definition) which is very important, if u are interested you can read more of GOF principles.

GOF is categorized into three

  • Creational
  • Behavioral
  • Structural
Way to Remember this is Chocolates are Bitter and Sweeter.

Chocolates - CREATIONAL
Bitter          - BEHAVIORAL
Sweeter      - STRUCTURAL

What is Creational Pattern ?
                      Solution that denotes how objects should be created to solve a problem
What is Behavioral Pattern ?
                    Solution that denotes how objects should be Communicated to solve a problem
What is Structural Pattern ?
                    Solution that denotes how entities should be related to solve a problem

    If you can remember these definitions and relate what it means, then you are half way through. Let us discuss about each and every category in following blogs.






No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Build Bot using LUIS