GOF (Structural Design Pattern) : BY: Suleman Junaid
GOF (Structural Design Pattern) : BY: Suleman Junaid
(STRUCTURAL DESIGN
PATTERN)
BY: Suleman Junaid
GOF(GANG OF FOUR)
• The Gang of Four are the four authors of the book, "Design Patterns:
Elements of Reusable Object-Oriented Software".
• The four authors were Erich Gamma, Richard Helm, Ralph Johnson and
John Vlissides.
STRUCTURAL PATTERN
• The second type of design pattern is the structural pattern. Structural
patterns provide a manner to define relationships between classes or
objects.
STRUCTURAL PATTERN INCLUDE
• Adaptor
• Bridge
• Decorator
• Facade
• Flyweight
• Proxy
DECORATOR
• The decorator pattern is a design pattern that extends the functionality of
individual objects by wrapping them with one or more decorator classes.
These decorators can modify existing members and add new methods
and properties at run-time.
• Design Patterns - Decorator Pattern. Decorator pattern allows a user to add
new functionality to an existing object without altering its structure. This
type of design pattern comes under structural pattern as this pattern acts
as a wrapper to existing class.
EXAMPLE
• An example of the decorator pattern could be used in a computer system
used by a company that provides vehicles for hire during track days. Such a
company could own a fleet of cars and motorcycles for hire. Each vehicle
could be represented by an instance of a class that inherits from the Vehicle
class. This would define key properties such as make, model, hire price and
number of laps permitted.
• Vehicles in the track day system will not be available for hire if they have
faults. However, if no faults are known, the vehicle's object would be
wrapped by the Hireable class. This class would be a decorator that holds a
reference to the underlying vehicle and adds extra functionality to allow
logging of the details of hire periods. Further decorators could be added
according to business rules. For example, special offer decorators could be
added to automatically reduce the hire price or increase the number of laps
that may be driven.
• Implementing the Decorator Pattern
DECORATOR
• The decorator allows you to modify object dynamically.
• Simplifies code because you add functionality using many simple classes
• Rather than rewrite old code you can extend with new code
FACADE
• The facade pattern is a design pattern that is used to simplify access to
functionality in complex or poorly designed subsystems. The facade class
provides a simple, single-class interface that hides the implementation
details of the underlying code. It is accessed by singleton pattern.
EXAMPLE
• One example use of the facade pattern is for integrating a web site with a
business application. The existing software may include large amounts of
business logic that must be accessed in a particular manner. The web site
may require only limited access to this business logic. For example, the web
site may need to show whether an item for sale has reached a limited level
of stock.
CREATIONAL VS STRUCTURAL VS
BEHAVIORAL
Creational patterns Structural design Behavioral pattern
are design patterns patterns are design explains how objects
that deal with object patterns that ease interact. It describes
creation the design by how different objects
mechanisms and are identifying a simple and classes send
used in situations way to realise messages to each
when basic form of relationships other to make things
object creation between entities or happen and how
could result in design defines a manner for the steps of a task
problems or increase creating relationships are divided among
complexity of a between objects. different objects.
code base. Where Creational
patterns mostly
describe a moment
of time (the instant of
creation), and