Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Design pattern
1. DESIGN PATTERN AND ITS
APPLICATIONS
BY
SWEKSHA PANDEY 11115041
GAYATRI THAKUR 11115028
Major project-2015 (NIT Raipur)
2. In our project we have implemented several softwares by taking
advantages of design patterns. We have used java and developed
several smaller softwares like calculator using factory pattern,
degree Fahrenheit conversion using adapter pattern, matching
colored shapes with its name using bridge pattern etc.
Main purpose of the project was to develop an interactive
platform for learning design pattern. So we have made a website
using php for learning design pattern and all the running
applications are attached to this tutorial.
Major project-2015 NIT Raipur
3. To learn usage of design pattern and to take
advantages of design pattern in software development.
Introducing modularity in softwares and making
code readable.
Providing solution to common problem that may
appear during software development.
Major project-2015 NIT Raipur
4. Origin of design pattern
In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and
John Vlissides published a book titled Design Patterns - Elements of
Reusable Object-Oriented Software which initiated the concept
of Design Pattern in Software development.
Major project-2015 NIT Raipur
5. Common problems in software
development:
1. How to ensure that my class can be instantiated only once.
2. How to combine two incompatible classes.
3. How to decouple implementation of interface by different
classes
4. How to add additional functionality to a class without
changing functionality of existing class
Major project-2015 NIT Raipur
6. Design patterns are reusable solution to common problems
that software developers face during software development.
Design pattern is more advantageous if we use it with object
oriented programming languages like java and C++.
Major project-2015 NIT Raipur
7. Types of design pattern
There are many design patterns but all can be categorized
into three groups
1. Creational design pattern
2. Structural design pattern
3. Behavioral design pattern
Major project-2015 NIT Raipur
8. This design pattern provides the best possible way to create and
instantiate an object.
It provides a more flexible way to create an object and nature of
object can change with nature of program.
Three main types of creational design patterns are:
1.1. Singleton Design Pattern
1.2. Factory Method
1.3. Abstract Factory Method
Major project-2015 NIT Raipur
9. 1.1 Singleton Pattern
Singleton is a class that can be instantiated only once. Hence only a
single instance of this class can be created.
It can be used at the places where we want to restrict creation of
multiple instances of a class.
Major project-2015 NIT Raipur
10. Singleton pattern: Implementation 1
This implementation contains server client application in which
server is using singleton class.
So client can request only one a single instance of server.
Major project-2015 NIT Raipur
12. 1.2 Factory Method
A factory class instantiates and returns a particular type
of object based on the data passed to the factory.
A factory is a class that is used to encapsulate creation
code of object.
Major project-2015 NIT Raipur
13. Factory Method: Implementation 2
This implementation contains a simple calculator that is
developed using factory pattern.
When we pass data for a particular operator then factory
returns object for that operator.
That object is used for calling methods for that operator
Major project-2015 NIT Raipur
15. 1.3 Abstract Factory Method
This factory is also known as factory of factories.
In abstract factory an interface is responsible for creating
factory of related object without specifying their classes.
Major project-2015 NIT Raipur
16. Abstract Factory: Implementation 3
This implementation consist of a small application in
which choosing an animal displays its family and details
about that animal.
Family is basically the factory returned by abstract
factory method.
Major project-2015 NIT Raipur
18. Structural Patterns describe how objects and classes can be combined
to form larger structures. In software engineering, structural design
patterns are design patterns that ease the design by identifying a
simple way to realize relationships between entities.
Types of structural design patterns are:
2.1 Adapter pattern
2.2 Decorator pattern
2.3 Bridge pattern
2.4 Façade pattern
Major project-2015 NIT Raipur
19. 2.1 Adapter Pattern
Adapter pattern works as a bridge between two
incompatible interfaces.
This pattern combines the capability of two independent
interfaces.
Major project-2015 NIT Raipur
20. Adapter Pattern: Implementation 4
In this implementation we have made a media player
which can play both .wav and .mp3 songs.
We are using an adapter class for combining features of
two types of songs.
Major project-2015 NIT Raipur
22. 2.2 Decorator Pattern
Decorator pattern allows a user to add new functionality
to an existing object without altering its structure.
This pattern creates a decorator class which wraps the
original class and provides additional functionality
keeping class methods signature intact.
Major project-2015 NIT Raipur
23. Decorator Pattern: Implementation 5
Here we have created an applet for depicting decorator
pattern. In this application clicking on buttons add extra
description to an existing description about an animal.
Major project-2015 NIT Raipur
25. 2.3 Bridge method
This pattern involves an interface which acts as a bridge
which makes the functionality of concrete classes
independent from interface implementer classes.
It decouples an abstraction from its implementation so that
the two can vary independently
Major project-2015 NIT Raipur
26. Bridge method: Implementation 6
This implementation contains colored shapes and a bridge
is maintained between color and shapes classes.
With the help of this bridge it is possible to match names
with colored shapes.
Major project-2015 NIT Raipur
28. 2.4 Façade Pattern
Façade is a face of the building.
It hides the complexities of the system and provides an
interface to the client from where the client can access
the system.
Major project-2015 NIT Raipur
29. Façade pattern: Implementation 7
This implementation contains an applet which calculate
2nd , 4th , 6th, 8th , and 9th root of a number. It uses façade
pattern to combine square root and cube root methods for
calculating other roots.
Major project-2015 NIT Raipur
31. 3. Behavioral design pattern
Major project-2015 NIT
Raipur
Behavioral design pattern provides a way to
communicate between objects , so it provides flexibility
for communication between objects by either creating
loose-coupling or hiding implementation detail to reduce
communication complexity.
32. 3.1 Template Pattern
In Template pattern, an abstract class exposes defined
way(s)/template(s) to execute its methods.
Its subclasses can override the method implementation as
per need but the invocation is to be in the same way as
defined by an abstract class.
Major project-2015 NIT Raipur
33. Template Pattern: Implementation 8
This is a simple implementation in which template for
hockey and cricket are created and order of execution of
events are same in both.
Order of events are initialize the game, enjoy the game
and finish the game.
Major project-2015 NIT Raipur
35. 3.2Chain Responsibility Design Pattern
Major project-2015 NIT Raipur
It gives opportunities to the objects to handle
request.
Each object handle specific request.
For example:-Handling different numbers by positive
handler , negative handler and zero handler.
36. Chain : Implementation 9
Positive handler to handle positive numbers
Major project-2015 NIT Raipur
38. 3.3 Mediator Design Pattern
Major project-2015 NIT Raipur
Communication between two objects become more
complex because of internal structure of objects, so mediator
Used to create loose- coupling between objects.
For example application for communication between two
users:
40. 3.4 Strategy Design Pattern
Major project-2015 NIT Raipur
Handle multiple algorithms with in a class or change
execution at run time.
For example file compressor application:
This application used to compress file in GIP or GZIP
or RAR so it has class to handle multiple algorithms
and change execution at run time.
42. 3.5 Iterator Design Pattern
Major project-2015 NIT Raipur
Iterator design pattern is used to access data from large
collection of data.
Accessing data without exposing it’s internal data
structure.
For example accessing a channel from collection of channel
44. 3.6 Interpreter design pattern
Major project-2015 NIT Raipur
This design pattern assign a value in place of complex
expression or grammar.
Like infix or postfix expression evaluated and assign a
specific value.
This pattern map a domain to a language, the language
to a grammar , a grammar to a object.
45. Interpreter pattern: Implementation 13
Application of interpreter design pattern: A parser from
roman to english digit
Major project-2015 NIT Raipur
46. 3.7 Observer design pattern
Major project-2015 NIT Raipur
Observer design pattern is used to hold one-to-
many relationship between objects.
In this relation if one state change it will notify to
another observers.
For example suppose three observers to observe
Hexadecimal , octal , binary numbers:
49. Purpose of tutorial
This tutorial has been prepared for the developers to
provide best solutions to certain problems faced during
software development and for un-experienced developers
to learn software design in an easy and faster way.
Major project-2015 NIT Raipur
50. Advantage of design pattern:
1.They are reusable in multiple projects.
2.They provide the solutions that help to define the system
architecture.
3.They capture the software engineering experiences.
4.They provide transparency to the design of an application.
5.They are well-proved and testified solutions since they have
been built upon the knowledge and experience of expert
software developers.
Major project-2015 NIT Raipur
51. Disadvantages of design pattern:
1. Complex in nature
2. Not always decrease understandability of design or
code. They can decrease understandability
3. Picking the correct design pattern and understanding
how to implement that pattern to our scenario is difficult.
Major project-2015 NIT Raipur