Wednesday, October 4, 2017

Builder Patten


When the request reaches code responsible for creating objects, It will call the director/composer, Then composer will call the builder, Then builder will  call appropriate concrete creator (here sedan creator) Then concrete creator will call all the part creators. Then  Part creator will create the parts and if required it will connect to database for raw materials, Then return it to the creator.  Then creator will return it to the builder. Then builder will return it to the director. Then director will assemble each parts creates the object and return it to the requester.

Notes:
  • Usually builder patter is used when the construction process is same for all concrete creators even though each part creation is different for each creators. 
  • The original requester is in touch only with director. here director is in touch with builder. If tomorrow builder changes the concrete creator or concrete creator changes its  part creators all these changes will not affect the original requester. 
check here for grafffitoid version of other design patterns

Factory Method Pattern


When request reaches code responsible for creating objects,  It will call the creator. Then the creator will call appropriate concrete creator (here sedan Creator). Then the concrete creator will creates the car and if required it is connects to database for each units then return it to the original requester.

Notes:

It is similar to abstract factory pattern, but there are few difference
  • In abstract factory pattern, original requester was requesting for more than one type of related objects(car and cycle). Here only single object (only car) even though it is not mandatory.
  • In abstract factory pattern, more level of abstraction is there and it is helping us to change the factory itself. Here only the product we are able change not the factory.
check here for grafffitoid version of other design patterns

Abstract Factory Pattern


When the request reaches the code responsible for creating objects. It will call the abstract factory. Then the abstract factory will call the appropriate factory (here Factory I) responsible for creating objects. Then the factory will call car creator and cycle creator respectively. They will create the car and cycle and  If required as shown in picture it is connecting to database for each units and assemble it and return it to the requested person.

Notes
  •  The original requester does not know which factory the abstract factory is going to call they are only in contact with abstract factory If tomorrow the abstract factory changes its factory or factory changes its object creators it will not affect the original requester.
  • Original requester requests for more than one type of related or depended objects (here car and cycle). 
check here for grafffitoid version of other design patterns

Design Patterns

There is lot of well known design patterns and there are more than thousand resources available on Internet regarding these patterns. Here I picked few of them and making graffitoid versions

These are my choice


  1.  Abstract Factory 
  2.  Factory Method
  3.  Builder

Most of them I used the common example used to explain these patterns, Requesting for car bike and cycle objects :)