design pattern

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

Upload: adel-al-ajami

Post on 05-Dec-2014

264 views

Category:

Technology


0 download

DESCRIPTION

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

TRANSCRIPT

04/09/2023

Mhd Adel Alajami 1

DESIGN PATTERN

Mhd Adel Alajami

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

04/09/2023

3

Software Development

Mhd Adel Alajami

04/09/2023

4

Mhd Adel Alajami

Software Development

Softwareindustry is like other industry

04/09/2023

5

Mhd Adel Alajami

Software Development

04/09/2023

6

Mhd Adel Alajami

Software Development

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

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

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

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

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 ?

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

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

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

04/09/2023

15

State Machine

Mhd Adel Alajami

04/09/2023

16

Classic Way – Without Pattern

Mhd Adel Alajami

04/09/2023Mhd Adel Alajami

17

Classic Way – Without Pattern

04/09/2023Mhd Adel Alajami

18

Classic Way – Without Pattern

04/09/2023

19

We Need Another State

Mhd Adel Alajami

SoftwareChanges

04/09/2023

20

We Need Another State

Mhd Adel Alajami

We Need a Pattern Design

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

04/09/2023

22

Think of Each State as an object

Mhd Adel Alajami

04/09/2023

23

Mhd Adel Alajami

Think of Each State as an object

04/09/2023

24

Class Diagram

Mhd Adel Alajami

04/09/2023Mhd Adel Alajami

25

Implement State Design Pattern

04/09/2023Mhd Adel Alajami

26

Implement State Design Pattern

04/09/2023Mhd Adel Alajami

27

Implement State Design Pattern

04/09/2023

28

Advantage

Mhd Adel Alajami

04/09/2023

29

Singleton Design Pattern

Mhd Adel Alajami

Prevent Creation Multi Instance

Provide Global Access

04/09/2023

30

Singleton Uses

Mhd Adel Alajami

04/09/2023

31

Why can’t I Just Instantiate One?

Mhd Adel Alajami

No Protection

04/09/2023

32

Prevent Instantiation

Mhd Adel Alajami

Can’t Instantiation From Outside

04/09/2023

33

Prevent Instantiation

Mhd Adel Alajami

But Every Time Will Create New Instance !!!

04/09/2023

34

Mhd Adel Alajami

Prevent Instantiation

That Ok

04/09/2023

35

Class Diagram

Mhd Adel Alajami

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

04/09/2023

37

Mhd Adel Alajami

What About Singleton With Multithreading

synchronized

04/09/2023

38

Before Façade Design Pattern

Mhd Adel Alajami

Client Classes

Subsystem classes

Need to communicatewith

04/09/2023

39

Façade Design Pattern

Mhd Adel Alajami

Client Classes

Subsystem classes

Facade

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

41

Any Questions ?

04/09/2023Mhd Adel Alajami