Oose Presentation
Oose Presentation
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.
Creational
Structural
Behavioral
Creational 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
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: