0% found this document useful (0 votes)
0 views8 pages

Design Patterns

Design patterns are reusable solutions to common software design problems, providing templates for improving code organization, scalability, and maintainability. They are categorized into creational, structural, and behavioral patterns, each addressing different aspects of object interaction and architecture. In contrast, architectural patterns focus on the overall structure and organization of an entire software system.

Uploaded by

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

Design Patterns

Design patterns are reusable solutions to common software design problems, providing templates for improving code organization, scalability, and maintainability. They are categorized into creational, structural, and behavioral patterns, each addressing different aspects of object interaction and architecture. In contrast, architectural patterns focus on the overall structure and organization of an entire software system.

Uploaded by

Nada Ibrahim
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Design Patterns

A design pattern is a reusable solution to a common problem that


occurs in software design. It provides a template or guideline for solving
problems related to software architecture and object interactions. Design
patterns are not specific pieces of code but rather high-level strategies
that can be applied across different programming languages and projects
to make code more organized, scalable, and maintainable.

Key Characteristics:

1. Reusability: Design patterns are general solutions that can be


adapted to different problems in various contexts.

2. Best Practices: They are based on the experience of software


developers and represent the best ways to solve specific types of
problems.

3. Communication: Design patterns create a shared vocabulary


among developers, allowing them to communicate solutions more
effectively.

What does the pattern consist of?

Most patterns are described very formally so people can reproduce them
in many contexts. Here are the sections that are usually present in a
pattern description:

 Intent of the pattern briefly describes both the problem and the
solution.

 Motivation further explains the problem and the solution the


pattern makes possible.

 Structure of classes shows each part of the pattern and how they
are related.

 Code example in one of the popular programming languages


makes it easier to grasp the idea behind the pattern.

Types of Design Patterns:

Design patterns are commonly grouped into three main categories:

1. Creational Patterns
These patterns provide object creation mechanisms that increase
flexibility and reuse of existing code.

1 | Page
o Singleton: Ensures that a class has only one instance and
provides a global access point to that instance.

o Factory Method: Defines an interface for creating objects


but allows subclasses to alter the type of objects that will be
created.

2 | Page
o Builder: Separates the construction of a complex object from
its representation, allowing the same construction process to
create different representations.

3 | Page
2. Structural Patterns
explain how to assemble objects and classes into larger structures,
while keeping these structures flexible and efficient.

o Adapter: Allows incompatible interfaces to work together by


wrapping an object with a new interface.

o Facade: Provides a simplified interface to a complex


subsystem.

4 | Page
o Decorator: Adds behaviour to individual objects without
affecting the behaviour of other objects from the same class.

3. Behavioral Patterns
These patterns focus on communication and interaction between
objects.

o Observer: Defines a one-to-many dependency between


objects so that when one object changes state, all its
dependents are notified.

5 | Page
o Strategy: Allows selecting an algorithm at runtime by
defining a family of algorithms and making them
interchangeable.

o Command: Encapsulates a request as an object, allowing


parameterization of clients with different requests, queuing of
requests, and logging.

6 | Page
The key difference between design patterns and architectural
patterns lies in their scope and the level at which they are applied in
software development.

1. Design Patterns:

 Scope: Focused on solving specific problems within a software


module or component.

 Granularity: Low-level, targeting the structure and behaviour of


objects and classes.

 Purpose: To provide reusable solutions for common problems in


software design, typically focused on improving code organization,
flexibility, and maintainability.

 Examples:

o Creational Patterns (e.g., Singleton, Factory, Builder)

o Structural Patterns (e.g., Adapter, Decorator, Composite)

o Behavioral Patterns (e.g., Observer, Strategy, Command)

 Use Case: For instance, if you're designing a user interface and


want to decouple the logic of managing the UI elements, a design
pattern like the Observer pattern could be used.

2. Architectural Patterns:

 Scope: Concerned with the overall structure and high-level


organization of an entire software system.

 Granularity: High-level, focusing on how components interact and


are structured.

 Purpose: To provide solutions for organizing the architecture of a


large system or application, focusing on aspects like scalability,
performance, and maintainability.

 Examples:

o Layered Architecture (e.g., Presentation, Business, Data


Access layers)

o Microservices Architecture

o Model-View-Controller (MVC)

o Event-Driven Architecture

7 | Page
 Use Case: For example, if you're building a large web application
and need to decide how to structure the system to handle scalability
and modularity, you might opt for a Microservices Architecture.

Summary:

 Design Patterns are about how individual components (like classes


and objects) are structured and interact.

 Architectural Patterns address how the entire system is


structured and designed at a higher level, affecting the whole
application.

8 | Page

You might also like