0% found this document useful (0 votes)
62 views

Oose Presentation

The document discusses design patterns. It begins by introducing design patterns and their purpose. It then covers three main categories of design patterns: creational, structural, and behavioral. Under creational patterns, it discusses the factory pattern in more detail. It provides an example implementation of the factory pattern using interfaces and classes. For structural patterns, it covers the bridge pattern, explaining its purpose, advantages, and providing a UML diagram and code example. It also discusses the visitor pattern under behavioral patterns.

Uploaded by

Shafiq Ul Umar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Oose Presentation

The document discusses design patterns. It begins by introducing design patterns and their purpose. It then covers three main categories of design patterns: creational, structural, and behavioral. Under creational patterns, it discusses the factory pattern in more detail. It provides an example implementation of the factory pattern using interfaces and classes. For structural patterns, it covers the bridge pattern, explaining its purpose, advantages, and providing a UML diagram and code example. It also discusses the visitor pattern under behavioral patterns.

Uploaded by

Shafiq Ul Umar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Design Patterns

Group Members
 Bilal Khan
 Abdul Qadir
 Ammar Ahmad
 Shafiq ul Umar
 Awab Khan
What are Design Patterns ??
“Some body has already solve your problem”
 A design pattern is a documented best practice or core of a solution that has
been applied successfully in multiple environments to solve a problem that
recurs in a specific set of situations.

 It is “a recurring solution to a common problem in a given context and system


of forces.”
 A design pattern is not an invention. A design pattern is rather a documented
expression of the best way of solving a problem that is observed or discovered
during the study or construction of numerous software systems
Categories of Design Patterns

 Creational

 Structural

 Behavioral
Creational pattern

 Creational design patterns are design patterns that deal


with object creation mechanisms, trying to create objects
in a manner suitable to the situation.. Creational design
patterns solve this problem by somehow controlling this
object creation.
 These design patterns provide a way to create objects
while hiding the creation logic, rather than instantiating
objects directly using new operator. This gives program
more flexibility in deciding which objects need to be
created for a given use case.
  Factory Pattern

 In Factory pattern, we create object without


exposing the creation logic to the client and refer
to newly created object using a common
interface.
 Factory Method is a creational design pattern
that provides an interface for creating objects in
a superclass, but allows subclasses to alter the
type of objects that will be created.
Factory Pattern

 Statement:
 When a client object does not know which class to instantiate, it can
make use of the factory method to create an instance of an appropriate
class from a class hierarchy or a family of related classes. The factory
method may be designed as part of the client itself or in a separate
class. The class that contains the factory method or any of its subclasses
decides on which class to select and how to instantiate it.
Implementation

 We'recreate a Shape interface and


concrete classes implementing the Shape
interface
 FactoryPatternDemo, our demo class will
use ShapeFactory to get a Shapeobject. It
will pass information (CIRCLE /
RECTANGLE / SQUARE) to ShapeFactory to
get the type of object it needs.
UML
Code
Structure Design Pattern

Structuraldesign patterns are concerned with how


classes and objects can be composed, to form larger
structures. The structural design patterns simplifies
the structure by identifying the relationships. These
patterns focus on, how the classes inherit from each
other and how they are composed from other
classes.
Bridge Pattern

A Bridge Pattern says that just "decouple


the functional abstraction from the
implementation so that the two can vary
independently".
 TheBridge Pattern is also known as Handle
or Body.
Advantages
 Itenables the separation of implementation from
the interface.
 It improves the extensibility.
 Itallows the hiding of implementation details
from the client.
Usage
 When you don't want a permanent binding between
the functional abstraction and its implementation.
 When both the functional abstraction and its
implementation need to extended using sub-classes.
 It is mostly used in those places where changes are
made in the implementation does not affect the
clients.
UML
Code
Output
Visitor Design Pattern
What is Visitor Design Pattern?

 Visitordesign pattern is one of the behavioral


design patterns. It is used when we have to
perform an operation on a group of similar kind of
Objects. With the help of visitor pattern, we can
move the operational logic from the objects to
another class.
Parts of Visitor Design Pattern

A method called Visit() which is implemented by


the visitor and is called for every element in the
data structure.

 Visit
able classes providing Accept() methods that
accept a visitor
UML Diagram Visitor design pattern
Design Components
 Client : The Client class is a consumer of the
classes of the visitor design pattern. It has access
to the data structure objects and can instruct
them to accept a Visitor to perform the
appropriate processing.
 Visitor: This is an interface or an abstract class
used to declare the visit operations for all the
types of visitable classes.
Design Components
 Concrete Visitor : For each type of visitor all the visit
methods, declared in abstract visitor, must be
implemented. Each Visitor will be responsible for different
operations.
 Visitable : This is an interface which declares the accept
operation. This is the entry point which enables an object
to be “visited” by the visitor object.
 Concrete Visitable : These classes implement the
Visitable interface or class and defines the accept
operation. The visitor object is passed to this object using
the accept operation.
Advantages :
 Ifthe logic of operation changes, then we
need to make change only in the visitor
implementation rather than doing it in all
the item classes.
 Adding a new item to the system is easy, it
will require change only in visitor interface
and implementation and existing item
classes will not be affected.
Disadvantages :
 We should know the return type of visit()
methods at the time of designing otherwise
we will have to change the interface and
all of its implementations.
 Ifthere are too many implementations of
visitor interface, it makes it hard to
extend.
Code:

You might also like