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

Design Patterns in Software Engineering

Uploaded by

Ali Hamza
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Design Patterns in Software Engineering

Uploaded by

Ali Hamza
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Software Design Patterns

Musa
Muhammad Arslan
Ali Hamza
Types

1. Creational design patterns


2. Structural design patterns
3. Behavioral design patterns
Creational Design Patterns

1. Singleton Design pattern


2. Factory Design pattern
3. Builder Design pattern
4. Prototype Design pattern
Singleton Design Patterns

creational pattern that ensures a class has only


one instance
Singleton Design Pattern
Example

Database connection
Singleton Design Patterns
Implementation

• Private constructor
• Public static method
• Private static instance
Singleton Design Patterns
Benefits

• Improve performance
• Reusability
Singleton Design Patterns
Threats

• Difficult unit testing


• Hidden dependencies
Factory Design Pattern

Provides an interface to create an


object;
Factory Design Pattern
Implementation

• Abstract class [super class]


• Concrete subclass
• Factory class
Factory Design Pattern
Example

• Vehicle[superclass]
• Car, Truck[subclass]
• Vehicle factory
Factory Design Pattern
Benefits

• Encapsulation
• Polymorphism
• Reusability
Builder Design Pattern

Create an object step by step


Builder Design Pattern
Implementation

• Product
• Builder
• Concrete builder
• Director
Builder Design Pattern
Example
• Product [car]
• Builder [car factory]
• Concrete builder [ford car builder]
• Director
Builder Design Pattern
Advantages
• Encapsulation
• Reusability
• Code readability
Prototype Design Pattern
• Crete a new object by copying an
existing object
Prototype Design Pattern
• Crete a new object by copying an
existing object
Prototype Design Pattern
Advantages
• Encapsulation
• Improve performance
Structural Pattern
Behavioral Pattern

• Decorator Pattern
• Facade Pattern
• Adaptor Pattern
Decorator Pattern
• Adds behavior to objects dynamically
• Provide a flexible alternative to sub-classing
• Enhances reusability by allowing behaviors to be
added without altering the object
Facade Pattern
• Provides a simplified interface to a complex system
• Provide a unified interface to a set of interfaces
• Makes it easier for users to use and interact with the
system with minimal effort
Adaptor Pattern
• It allows objects with incompatible interfaces to work
together
• Class Adaptor and Object Adaptor
• Increases complexity by adding an extra layer of
abstraction which is good for security
Behavioral Pattern
Behavioral Pattern

• Observer Pattern
• Strategy Pattern
• Command Pattern
1. Observer Pattern
• It defines one-to-many dependency
between subject and observers.
• When one object changes state, all its
dependents are notified and updated
automatically.
• Example Weather App
2. Strategy Pattern
• It allows to do something in many ways.

• It enables selecting an algorithm at runtime.

• Strategy and Context

• Example Payment Method


3. Command Pattern

• Invoker
• Command
• Receiver
Advantages
• Promote Reusability

• Enhance Maintainability

• Enhance Readability

• Speed Up Development

• Reduce Errors and Bugs:


THANK YOU

You might also like