0% found this document useful (0 votes)
19 views7 pages

Design Patterns

Design patterns are reusable solutions to common software design problems that enhance code maintainability, scalability, and efficiency. They are categorized into creational, structural, and behavioral patterns, with examples including Singleton, Factory, Observer, and Strategy patterns. Each pattern addresses specific challenges in software design, such as managing object creation and defining dependencies between objects.

Uploaded by

Motuma Lalisa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

Design Patterns

Design patterns are reusable solutions to common software design problems that enhance code maintainability, scalability, and efficiency. They are categorized into creational, structural, and behavioral patterns, with examples including Singleton, Factory, Observer, and Strategy patterns. Each pattern addresses specific challenges in software design, such as managing object creation and defining dependencies between objects.

Uploaded by

Motuma Lalisa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

3.

4 Design Patterns

Understanding Common Software


Design Patterns
What are Design Patterns?
• - **Design patterns** are reusable solutions
to common software design problems.
• - They help improve code maintainability,
scalability, and efficiency.
• - Design patterns are categorized into three
types:
• 1. **Creational**: Managing object creation
(Singleton, Factory, etc.).
• 2. **Structural**: Organizing objects and
classes (Adapter, Decorator, etc.).
Singleton Pattern
• - Ensures only **one instance** of a class
exists.
• - Commonly used in database connections,
logging, and configuration settings.
• - Example in Python:

• class Singleton:
• _instance = None
Factory Pattern
• - Creates objects without specifying the exact
class.
• - Useful when dealing with multiple related
object types.
• - Example in Python:

• class AnimalFactory:
• def get_animal(self, type):
• if type == 'Dog':
Observer Pattern
• - Defines a dependency between objects, so
when one changes, others are notified.
• - Used in event-driven systems like GUI
applications.
• - Example in Python:

• class Observer:
• def update(self, message):
• print(f'Observer received: {message}')
Strategy Pattern
• - Defines a family of algorithms and lets the
client choose one at runtime.
• - Helps in designing flexible systems with
interchangeable behaviors.
• - Example in Python:

• class Strategy:
• def execute(self):
• pass
Conclusion
• - **Design patterns** help solve common
coding problems efficiently.
• - The **Singleton pattern** ensures a single
instance.
• - The **Factory pattern** simplifies object
creation.
• - The **Observer pattern** manages
dependent objects dynamically.
• - The **Strategy pattern** enables
interchangeable behaviors.

You might also like