Top Banner
DESIGN PATTERN Mhd Adel Alajami 01/19/2022 Mhd Adel Alajami 1
41

Design pattern

Dec 05, 2014

Download

Technology

Adel Al-ajami

Design Pattern is advance topic in Software Engineering and it is very important,you will find in this presentation explanation State Machine Pattern,Singleton Pattern and
Façade Pattern
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Design pattern

04/09/2023

Mhd Adel Alajami 1

DESIGN PATTERN

Mhd Adel Alajami

Page 2: Design pattern

04/09/2023

2

Agenda

Mhd Adel Alajami

Understanding the need for design patterns

What are design patterns

Using design patterns

State Design Patter

Singleton Design Patter

Façade Design Patter

Page 3: Design pattern

04/09/2023

3

Software Development

Mhd Adel Alajami

Page 4: Design pattern

04/09/2023

4

Mhd Adel Alajami

Software Development

Softwareindustry is like other industry

Page 5: Design pattern

04/09/2023

5

Mhd Adel Alajami

Software Development

Page 6: Design pattern

04/09/2023

6

Mhd Adel Alajami

Software Development

Page 7: Design pattern

04/09/2023

7

the need for design patterns

Mhd Adel Alajami

Software changes

We need to add a new features - boss

There is a change in the specification -

customer

We have found a big bug – team

Flexible code

Maintainable Code

Page 8: Design pattern

04/09/2023

8

Use Design Pattern

Mhd Adel Alajami

By learning theme

And then applying them in your OOP

designs

You will create more flexible and

maintainable code

Page 9: Design pattern

04/09/2023

9

Dealing with change

Mhd Adel Alajami

Software has lots of ways to change

There are many design pattern to deal

with changes

Design patterns address many of the

ways software changes over time

Page 10: Design pattern

04/09/2023

10

What are design pattern ?

Mhd Adel Alajami

Design patterns are general solutions to common problems

A pattern is a guideline for flexible and resilient code design

It does not go in detail of implementation

There is no DP for Banking system and other for games

It is a general solution for common problem in software development

Page 11: Design pattern

04/09/2023

11

Mhd Adel Alajami

“I have a problem, when one of my

object changes , I need to let all other

objects know. Is there a good way to do

that?”

This is a common problem in software

development

There is a proven method to solve it :

The Observer Pattern

What are design pattern ?

Page 12: Design pattern

04/09/2023

12

Where did DP come from ?

Mhd Adel Alajami

23 original pattern

Now, there are many patterns for many

different software problems

Page 13: Design pattern

04/09/2023

13

How To Use Design Pattern

Mhd Adel Alajami

A design pattern is not a library, module

or package

It’s a guideline for how to solve a

problem

Higher level than a library

First understand the pattern, and then

use its design in your software

Page 14: Design pattern

04/09/2023

14

Using Design Pattern

Mhd Adel Alajami

Ultimate in reuse

Build from years of software

development experience

Save times, and trial and error

Not reusing code, but reusing experience

Page 15: Design pattern

04/09/2023

15

State Machine

Mhd Adel Alajami

Page 16: Design pattern

04/09/2023

16

Classic Way – Without Pattern

Mhd Adel Alajami

Page 17: Design pattern

04/09/2023Mhd Adel Alajami

17

Classic Way – Without Pattern

Page 18: Design pattern

04/09/2023Mhd Adel Alajami

18

Classic Way – Without Pattern

Page 19: Design pattern

04/09/2023

19

We Need Another State

Mhd Adel Alajami

SoftwareChanges

Page 20: Design pattern

04/09/2023

20

We Need Another State

Mhd Adel Alajami

We Need a Pattern Design

Page 21: Design pattern

04/09/2023

21

Disadvantage

Mhd Adel Alajami

Is not really OO at all

Any additions require many change to

code

Difficult to understand all the state and

transitions

Violates open closed principle

Page 22: Design pattern

04/09/2023

22

Think of Each State as an object

Mhd Adel Alajami

Page 23: Design pattern

04/09/2023

23

Mhd Adel Alajami

Think of Each State as an object

Page 24: Design pattern

04/09/2023

24

Class Diagram

Mhd Adel Alajami

Page 25: Design pattern

04/09/2023Mhd Adel Alajami

25

Implement State Design Pattern

Page 26: Design pattern

04/09/2023Mhd Adel Alajami

26

Implement State Design Pattern

Page 27: Design pattern

04/09/2023Mhd Adel Alajami

27

Implement State Design Pattern

Page 28: Design pattern

04/09/2023

28

Advantage

Mhd Adel Alajami

Page 29: Design pattern

04/09/2023

29

Singleton Design Pattern

Mhd Adel Alajami

Prevent Creation Multi Instance

Provide Global Access

Page 30: Design pattern

04/09/2023

30

Singleton Uses

Mhd Adel Alajami

Page 31: Design pattern

04/09/2023

31

Why can’t I Just Instantiate One?

Mhd Adel Alajami

No Protection

Page 32: Design pattern

04/09/2023

32

Prevent Instantiation

Mhd Adel Alajami

Can’t Instantiation From Outside

Page 33: Design pattern

04/09/2023

33

Prevent Instantiation

Mhd Adel Alajami

But Every Time Will Create New Instance !!!

Page 34: Design pattern

04/09/2023

34

Mhd Adel Alajami

Prevent Instantiation

That Ok

Page 35: Design pattern

04/09/2023

35

Class Diagram

Mhd Adel Alajami

Page 36: Design pattern

04/09/2023

36

What About Singleton With Multithreading

Mhd Adel Alajami

To Avoid creation Multi Instance in Multithreading

Initialize Static Variable

Create instance even it’s not used

Disadvantage

Page 37: Design pattern

04/09/2023

37

Mhd Adel Alajami

What About Singleton With Multithreading

synchronized

Page 38: Design pattern

04/09/2023

38

Before Façade Design Pattern

Mhd Adel Alajami

Client Classes

Subsystem classes

Need to communicatewith

Page 39: Design pattern

04/09/2023

39

Façade Design Pattern

Mhd Adel Alajami

Client Classes

Subsystem classes

Facade

Page 40: Design pattern

04/09/2023

40

Benefits

Mhd Adel Alajami

Shields clients from subsystem classes; reduces

the number of objects that clients deal with.

Promotes weak coupling between subsystem

and its clients.

Helps in layering the system. Helps eliminate

circular dependencies.

Makes using the subsystem easier

Page 41: Design pattern

41

Any Questions ?

04/09/2023Mhd Adel Alajami