Design Patterns in Software Engineering
Design Patterns in Software Engineering
Musa
Muhammad Arslan
Ali Hamza
Types
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
• Vehicle[superclass]
• Car, Truck[subclass]
• Vehicle factory
Factory Design Pattern
Benefits
• Encapsulation
• Polymorphism
• Reusability
Builder Design Pattern
• 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.
• Invoker
• Command
• Receiver
Advantages
• Promote Reusability
• Enhance Maintainability
• Enhance Readability
• Speed Up Development