Skip to document

CS 3203 Software Engineering Lab 5

CS 3203 Software Engineering Lab 5
Course

Software Engineering (CS391)

174 Documents
Students shared 174 documents in this course
Academic year: 2021/2022
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
Fayoum University

Comments

Please sign in or register to post comments.

Preview text

Eng. Yossr - Eng. Esraa 1

Design Pattern

What Is a Design Pattern?

A design pattern provides a general reusable solution for the common problems that occur in software design. The pattern typically shows relationships and interactions between classes or objects. WHY? - The idea is to speed up the development process by providing well tested, proven development/design paradigm. - Design patterns are programming language independent strategies for solving a common problem. - That means a design pattern represents an idea, not a particular implementation. By using the design patterns, you can make your code more flexible, reusable, and maintainable. Types of Design Patterns Gang of Four categorized the Design Pattern into three main categories based on the three- problem area of software architecture. They are as follows: - 1. Creational patterns 2. Structural patterns 3. Behavioral patterns

1. Creational Design Patterns

What is the Creational Design Pattern in C#? Creational design patterns are design patterns that deal with object creation mechanisms i., trying to create objects in a manner that is suitable to a given situation. The Creational design patterns are categorized into two types: Object-creational patterns: The Object-creational patterns deal with object creation. Here, it defers part of its object creation to another object. Class-creational patterns: The Class-creational patterns deal with class-instantiation. Here, it defers its object creation to subclasses. When to use the Creational Design Pattern? Ex: Suppose a developer wants to create a simple DBConnection class to connect to a database and wants to access the database at multiple locations from code, generally what developer will do is create an instance of DBConnection class and use it for doing database operations wherever required. Which results in creating multiple connections from the database as each instance of DBConnection class will have a separate connection to the database. To deal with it, we create DBConnection class as a singleton class, so that only one instance of DBConnection is created and a single connection is established. Because we

CS 3203 Software Engineering (1) – 2020/2021 Lab ( 6 )

Eng. Yossr - Eng. Esraa 2

can manage DB Connection via one instance so we can control load balance, unnecessary connections, etc.

In real-time applications, the project is created with a lot of classes. A lot of classes mean we are going to deal with a lot of objects. If these objects creations are scattered on the client code, then it leads to a lot of complicated logic at the client code. The Creational Design Pattern helps us to centralize the object creation logic.

Examples of Creational Design Pattern: 1. Singleton Design Pattern 2. Factory Design Pattern 3. Abstract Factory Design Pattern 4. Builder Design Pattern 5. Fluent Interface Design Pattern 6. Prototype Design Pattern

2. Structural Design Patterns

What is Structural Design Pattern in C#?

Structural Design Patterns are design patterns that ease the design by identifying a simple way to realize the relationship among entities.

This design pattern is all about class and object composition. Structural class creation patterns use inheritance to compose interfaces. The structural object patterns define ways to compose objects to obtain new functionality.

The structural patterns describe how objects and classes can be combined to form larger structures.

When to use Structural Design Patterns in C#? Ex: When 2 interfaces are not compatible with each other and want to establish a relationship between them through an adapter it is called an adapter design pattern. Adapter pattern converts the interface of a class into another interface or class that the client expects, i. adapter lets classes works together that could not otherwise because of incompatibility. so, in these types of incompatible scenarios, we can go for the adapter pattern.

In real-time applications, sometimes we need to change the structure of a class or the relationship among the classes, but we do not want this change to be affected by the project. For example, if we have two classes let say user and product. And the product class is used inside the user class making one to many relationships between the User and Product. Tomorrow, the structure or the relationships between these two classes change. The customer now wants to keep away the product class from the User class, as they want to use the User and Product class independently. This is actually a structural change, and we don’t want this structural change to affect our project. This is where the Structural Design Pattern helps us.

Examples of Structural Design Patterns:

Was this document helpful?

CS 3203 Software Engineering Lab 5

Course: Software Engineering (CS391)

174 Documents
Students shared 174 documents in this course

University: Fayoum University

Was this document helpful?
Eng. Yossr - Eng. Esraa
1
Design Pattern
What Is a Design Pattern?
A design pattern provides a general reusable solution for the common problems that occur
in software design.
The pattern typically shows relationships and interactions between classes or objects.
WHY?
The idea is to speed up the development process by providing well tested, proven
development/design paradigm.
Design patterns are programming language independent strategies for solving a
common problem.
That means a design pattern represents an idea, not a particular implementation. By
using the design patterns, you can make your code more flexible, reusable, and
maintainable.
Types of Design Patterns
Gang of Four categorized the Design Pattern into three main categories based on the three-
problem area of software architecture. They are as follows: -
1. Creational patterns
2. Structural patterns
3. Behavioral patterns
1. Creational Design Patterns
What is the Creational Design Pattern in C#?
Creational design patterns are design patterns that deal with object creation mechanisms
i.e., trying to create objects in a manner that is suitable to a given situation.
The Creational design patterns are categorized into two types:
Object-creational patterns: The Object-creational patterns deal with object creation.
Here, it defers part of its object creation to another object.
Class-creational patterns: The Class-creational patterns deal with class-instantiation.
Here, it defers its object creation to subclasses.
When to use the Creational Design Pattern?
Ex:
Suppose a developer wants to create a simple DBConnection class to connect to a database
and wants to access the database at multiple locations from code, generally what
developer will do is create an instance of DBConnection class and use it for doing database
operations wherever required. Which results in creating multiple connections from the
database as each instance of DBConnection class will have a separate connection to the
database. To deal with it, we create DBConnection class as a singleton class, so that only
one instance of DBConnection is created and a single connection is established. Because we
CS 3203 Software Engineering (1) 2020/2021
Lab (6)