Uml DP

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

PROTOTYPE DESIGN

PATTERN &
ADAPTER DESIGN
PATTERN
CREATIONAL DESIGN PATTERN
• A creational design pattern provide
various object creation
mechanisms.
• These design patterns are used
when a decision must be made at
the time of instantiation of a class
(i.e. creating an object of a class).
• There are 6 types of creational
patterns, prototype design pattern
is one among those.
PROTOTYPE DESIGN
PATTERN:
• The Prototype Design Pattern is a creational pattern
that enables the creation of new objects by copying
an existing object.
• The prototype pattern is a creational design pattern
which is required when object creation is a time-
consuming, and costly operation
• A clone() method is the simplest approach to
implementing a prototype pattern.
• When the client needs a new object, instead of
directly instantiating a class, it requests a copy of an
existing object (the prototype).
COMPONENTS:
• Client : The Client is the code or module that
requests new object creation by interacting with
the prototype.
The Client invokes the Prototype interface, which is
the next component.
• Prototype Interface : This defines the method for
cloning objects and sets a standard that all
concrete prototypes must follow.
Prototype interface includes a clone method, used to
create a copy of all the objects.
• Concrete Prototype : The Concrete Prototype
details how the cloning process should work for
instances of that class and provides the specific
logic for the clone method.
6
WHEN TO USE & WHEN NOT TO USE
PROTOTYPE
DESIGN PATTERN?
• Use the Prototype pattern when creating
new objects is more complex or costly
than copying existing ones. Cloning can be
more efficient if significant resources are
needed.

• If object creation is simple and does not


involve significant resource consumption,
and there are no variations of objects,
using the Prototype pattern might be
unnecessary complexity.
STRUCTURAL DESIGN PATTERNS:
• Structural Design Patterns in software design focus on how
classes and objects are organized to form larger, functional
structures.
• These patterns help developers simplify relationships between
objects, making code more efficient, flexible, and easy to
maintain.
• By using structural patterns, you can better manage complex
class hierarchies, reuse existing code, and create scalable
architectures.
• The first kind in the classification of structural design patterns is
the Adapter Method Design Pattern.
ADAPTER METHOD DESIGN PATTERNS:
• Suppose you have two buddies, one of them
speaks French exclusively and the other English
exclusively. The language barrier prevents them
from communicating the way you want them to.
• You act as an adapter, translating messages
between them.
• Two incompatible interfaces or systems can
cooperate by using the adapter design pattern, a
structural design pattern.
• Because of incompatible interfaces, it serves as a
bridge between two classes that would not
otherwise be able to communicate.
• The Adapter Pattern is also known as Wrapper.
COMPONENTS
:
•Target Interface: Defines the interface expected by the
client. It’s the common interface that the client code interacts
with.
•Adaptee: The existing class or system with an incompatible
interface that needs to be integrated into the new system. It’s
the class or system that the client code cannot directly use due
to interface mismatches.
•Adapter: A class that implements the target interface and
internally uses an instance of the adaptee to make it
compatible with the target interface. It acts as a bridge,
adapting the interface of the adaptee to match the target
interface.
•Client: The code that uses the target interface to interact with
objects. It remains unaware of the specific implementation
PROS & CONS:
• By creating an adapter, you can reuse existing code
without needing to modify it. This promotes code reuse
and helps maintain a cleaner architecture.
• You can simply switch out multiple adapters to support
different interfaces without altering the underlying system.
• Introducing adapters can add a layer of complexity to your
system. Having multiple adapters can make the code
harder to navigate and understand.
• If not managed properly, the use of adapters can lead to
maintenance challenges. Keeping track of multiple
adapters for various interfaces can become cumbersome.
THANK YOU !!!

You might also like