Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.

Similar presentations


Presentation on theme: "Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design."— Presentation transcript:

1 Design Patterns -- Omkar

2 Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design patterns  Types of creational patterns  Advantages  Applications

3  When a problem occurs every time, we use Design Patterns in solving that problem rather than starting from the scratch.  By implementing the design rules and reusing the components, the chances of getting latent errors reduces to great extent  Design patterns helps in developing the application faster.  The more the developers become familiar with these patterns, the better will be the readability of the code.

4 The Design patterns can be classified as  Fundamental patterns  Creational patterns  Structural patterns  Behavioral patterns  Concurrency patterns  Event handling patterns  Architectural patterns

5 Creational design patterns deal with the operations related to object creation. Creational design patterns deal with the operations related to object creation. These patterns help in initialization of objects according to the situation. These patterns help in initialization of objects according to the situation. The abstract factory pattern, builder pattern, Factory method pattern, lazy initialization pattern, prototype pattern and the singleton pattern come under the category of the creational patterns. The abstract factory pattern, builder pattern, Factory method pattern, lazy initialization pattern, prototype pattern and the singleton pattern come under the category of the creational patterns.

6 Abstract factory pattern  The factories having the common features are grouped together without mentioning their specific concrete class.  Consider Personal information storing application  Create classes Phone_number, Zip_code.  Need to change functional code to extend the application for different country.  To avoid problem, group these classes which can accept variations.  Make the application more flexible  At the run time, the factory may be coupled with other concrete factories that have their own format

7 Applications of the Abstract Factory pattern  When the objects are to be created as a group or as a set which will make them more compatible  When the client should be abstracted from the details of the creation of objects  When providing the group of classes with their relationships and hiding the details of implementation Advantages It will make the application more flexible It will make the application more flexible The developer need not bother about the features that are going to be added The developer need not bother about the features that are going to be added At the run time it can add new features At the run time it can add new features Even the testing can be simplified by using this pattern Even the testing can be simplified by using this pattern

8 Builder pattern When the generation of objects become complex, we use builder pattern to simplify the process of object creation, by defining a class which will help to create objects of another class When the generation of objects become complex, we use builder pattern to simplify the process of object creation, by defining a class which will help to create objects of another class In this process, there will be only single main class which will have a main product with a number of classes within the product In this process, there will be only single main class which will have a main product with a number of classes within the product Consider Personal information storing application Consider Personal information storing application Collect details like starting and ending of appointment, location and the number of people attending Collect details like starting and ending of appointment, location and the number of people attending As there are chances of getting different types of data depending on the type of appointment, creating objects may turn complex As there are chances of getting different types of data depending on the type of appointment, creating objects may turn complex

9 Generally, this can be managed in two ways By creating constructer for every type of appointment By creating constructer for every type of appointment By having a constructer with much functionality By having a constructer with much functionality Problems using them If there are many number of constructors calling the methods, it becomes complex If there are many number of constructors calling the methods, it becomes complex If the functionality is high, the debugging turns very complex If the functionality is high, the debugging turns very complex In either of the way, creating a subclass will give problems In either of the way, creating a subclass will give problemsSolution we can use “AppointmentBuilder” class which will take the responsibilities of the “Appointment” class and can reduce the coding we can use “AppointmentBuilder” class which will take the responsibilities of the “Appointment” class and can reduce the coding

10  The Builder class can also validate the data passed to Appointment class and even enables to create sub class to the existing class Applications of the Builder pattern When the internal structure of the class looks very complex When the internal structure of the class looks very complex When the class needs some objects which are tough to access during creation When the class needs some objects which are tough to access during creationAdvantages Can help the objects to use the system resources easily for creation Can help the objects to use the system resources easily for creation The clients need to only access the Builder object for there resources which makes their work easy The clients need to only access the Builder object for there resources which makes their work easyDisadvantage The Builder and the product are considered to be tightly coupled The Builder and the product are considered to be tightly coupled

11 Factory method Pattern This pattern deals with creation of object. Which mainly depends on the sub class as it override the product which already exists This pattern deals with creation of object. Which mainly depends on the sub class as it override the product which already exists Consider Personal information storing application Consider Personal information storing application Collecting details like name of a person, phone number, appointment, address etc. Collecting details like name of a person, phone number, appointment, address etc. The data obtained may need to be modified if any of the data changes The data obtained may need to be modified if any of the data changes The application has to generate the fields according to the user, to modify the data, which will make the coding of application complex The application has to generate the fields according to the user, to modify the data, which will make the coding of application complex By making each of the field like address to use its own editors which can be very much useful in the modifications By making each of the field like address to use its own editors which can be very much useful in the modifications

12 The application is only responsible in requesting the editor which can be invoked for every field which needs to be modified The application is only responsible in requesting the editor which can be invoked for every field which needs to be modified This can be done by calling methods like getEditor which implements the Interface like ItemEditor This can be done by calling methods like getEditor which implements the Interface like ItemEditor The editor takes care of the data entered by the user whether the data is valid or not The editor takes care of the data entered by the user whether the data is valid or notApplications This pattern is specifically used when the type of object to be created is to be decided later This pattern is specifically used when the type of object to be created is to be decided later When we not aware at which time the object is to be created When we not aware at which time the object is to be created When we need many overloaded constructor with the same signature When we need many overloaded constructor with the same signature When we want a subclass to decide the type fo object to be created. When we want a subclass to decide the type fo object to be created.

13 References  [1] Creational Patterns: Creating Objects in an OO System.  http://www.phptr.com/articles/article.asp?p=26452&seqNum=1  [2] Design pattern (computer science)  http://en.wikipedia.org/wiki/Design_pattern_(computer_science)  [3] Patterns and Software: Essential Concepts and Terminology  http://www.cmcrossroads.com/bradapp/docs/patterns-intro.html  [4] Patterns-Discussion FAQ  http://g.oswego.edu/dl/pd-FAQ/pd-FAQ.html  [5] Design Patterns  http://www.objectmentor.com/writeUps/DesignPatterns

14 Thank You


Download ppt "Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design."

Similar presentations


Ads by Google