تحسين تصميم البرمجيات بإستخدام أنماط التصميم Software Design...

26
ماط ن دأم أ خ ت س إ ب ات ي ج م ر لب م أ ي م ص ت# ن ي س ج ت م ي م ص ت ل أSoftware Design Refinement Using Design Patterns

description

تحسين تصميم البرمجيات بإستخدام أنماط التصميم Software Design Refinement Using Design Patterns . The Requirements, Analysis, and Design, and Desgin Refiement Models. Use Case Diagrams/ Sequence Diagrams (the system level). Requirements Elicitation Process. Functional/ Nonfunctional - PowerPoint PPT Presentation

Transcript of تحسين تصميم البرمجيات بإستخدام أنماط التصميم Software Design...

Page 1: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

بإستخدام البرمجيات تصميم تحسينالتصميم أنماط

Software Design RefinementUsing Design Patterns

Page 2: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

The Requirements, Analysis, and Design, and Desgin Refiement Models

Static Analysis Dynamic Analysis

Functional/ NonfunctionalRequirements

Use Case Diagrams/Sequence Diagrams(the system level)

- Analysis Class Diagrams- State Diagrams/Refined Sequence Diagrams (The object level)

Requirements ElicitationProcess

The AnalysisProcess

Static ArchitecturalDesign

Dynamic Design

The DesignProcess:• Initial Design•Design Refinement

• Design Class Diagrams • Design Sequence Diagrams

Design Refinement • Refined Design Class Diagrams

Page 3: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Design Refinement• It is difficult to obtain a quality design from the

initial design• The initial design is refined to enhance design

quality using the software design criteria of modularity, information hiding, complexity, testability, and reusability.

• New components (or new classes) are defined and existing components (or classes) structures are refined to enhance design quality

• The design refinement step is an essential step before implementation and testing.

Page 4: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

التصميم تحسينجودة • على الحصول الصعب من ومن التصميم فى

األولي التصميمالتصميم جودة لتعزيز األولي التصميم تحسين ويتم

، نمطية من البرمجيات تصميم معايير باستخداموإعادة ، االختبار وقابلية ، والتعقيد ، المعلومات إخفاء

استخدام. ( وتعديل ( جديدة فئات أو جديدة عناصر تعريف يتم

( التصميم ( جودة لتعزيز فئات أو مكوناتالتنفيذ قبل أساسية خطوة هو تصميم تحسين خطوة

واالختبار

Page 5: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Design Class Diagram RefinementUsing Design Patterns

• Design Class Diagrams are further refined to enhance design quality (i.e., reduce coupling, increase cohesion, and reduce component complexity) using design patterns

• A design pattern is a documented good design solution of a design problem

• Repositories of design patterns were developed for many application domains (communication software, agent-based systems, web applications)

• Many generic design patterns were defined and can be used to enhance the design of systems in different application domains

Page 6: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

الفئات مخطط تصميم تحسينالتصميم أنماط بإستخدام

Page 7: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

What is a Design Pattern• What is a Design Pattern?

A design pattern describes a design problem which repeatedly occurred in previous designs, and then describes the core of the solution to that problem

• Solutions are expressed in terms of classes of objects and interfaces (object-oriented design patterns)

• A design pattern names, abstracts, and identifies the key aspects of a high quality design structure that make it useful for creating reusable object-oriented designs

Page 8: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Defining a Design Pattern• Design Patterns are documented in the literature

by a template consisting of the followingA Design Pattern has 5 basic parts:1. Name2. Problem3. Solution4. Consequences and trade-of of application5. Implementation: An architecture using a design

class diagram

Page 9: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Example ofPatternDefinition

The FaçadePatternProvidesAnInterfaceTo aSubsystem

Page 10: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

The Facade Pattern

• The class Facade is introduced as an interface to the whole subsystem.

• Any client class needs a service from any of the subsystem classes will be send the request to the facade class.

• All the subsystem interfaces are combined in one class

Page 11: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Example of Using the Design PatternDesign Patterns produce quality designs by reducing couplingExample of how a Façade Pattern reduces coupling

Page 12: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Another Example: The Strategy Pattern template

Page 13: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Another Example of Design Patterns

• The Strategy Pattern: lets the algorithm vary independently from clients that use it

Abstract ClassController Class

Control Strategy A Control Strategy B Control Strategy C

Default control Strategy

Page 14: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

The Strategy Pattern

• The Strategy Pattern Context class has multiple control strategies provided by the concrete strategy classes, or by the abstract strategy (by default)

• The pattern lets us vary the algorithm that implements a certain function during run time depending on the conditions of the system

• The Pattern reduces coupling by having the client class be coupled only to the context class

Page 15: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Example of using the Strategy Pattern: A Job Application System

• The complexity of class JobApplication is reduced by moving the validate() operation to the Strategy Pattern classes

HostValidator

validate()

(from patterns)

ManagerValidator

validate()

(from patterns)

WaitStaffValidator

validate()

(from patterns)

BartenderValidator

validate()

(from patterns)

BusValidator

validate()

(from patterns)

JobApplicantClient

main()runTest()

(from common)

Appl icantRuleFactory

getApplicantVal idationRule()

(from patterns)JobApplicantForm

JOB_MANAGER : int = 1JOB_WAIT_STAFF : int = 2JOB_BUSSER : int = 3JOB_BARTENDER : int = 4JOB_HOSTER : int = 5position : intname : Stringphone : Stringemail : StringyearsExp : Doublereference1 : Stringreference2 : Stringreference3 : Stringlegal : boolean = false

isLegal()setLegal()getPosition()setPosition()getName()setName()getPhone()setPhone()getEmail()setEmail()getYearsExp()setYearsExp()getReference1()setReference1()getReference2()setReference2()getReference3()setReference3()validate()

(from patterns)

FormValidator

successMessage : String = "\nThank you for submitting your job application."

isEmpty()validate()basicValidation()

(from patterns)

FormSuccess

success : boolean = falseresultMessage : String = nul l

FormSuccess()isSuccess()setSuccess()getResultMessage()setResultMessage()

(from common)

Page 16: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Examples of Design PatternsThe State Pattern

• The State Pattern: is a solution to the problem of how to make the behavior of an object depend on its state.

MultiStateOb

+CreateInitState()Setstate()

<<interface>>Statestate

ConcreteState 1 concreteState n

Oprn() Opr1()Opr2()

1..N

……………..N concrete stateclasses

Abstract State Class

Lets a mutli state class divide its responsibilities (Opr1(),Opr2(), and Oprn() on multiple state classes.

TheContextClass

For more Info, seehttp://home.earthlink.net/~huston2/dp/state.html

Current StateChangestate()Deletestate()

Page 17: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Examples of Design PatternsThe State Pattern

• The State pattern is a similar in structure to the Strategy Pattern but with different behavior or dynamics. the state objects are active one at a time depending on the actual state of the contect object.

• The structure is defined as follows:– Define a "context" class to present a single interface to the

outside world. – Define a State abstract base class. – Represent the different "states" of the state machine as derived

classes of the State base class. – Define state-specific behavior in the appropriate State derived

classes. – Maintain a pointer to the current "state" in the "context" class. – To change the state of the state machine, change the current

"state" pointer• State Transitions can be defined for each State class

Page 18: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Examples of Design Patterns

• The client class Multistateob would create the initial state object to provide the services of the initial state (it will set its current state to its initial state)

• The initial state object would sense the condition for state transition to a new state, when this occurs it would then create an object of the new state and destroy itself

• Each state object implements the transition, actions, and activities in the state it represents

Page 19: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Examples of Design PatternsThe State Pattern

Structure

                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

A Ceiling Fan Pull Chain Example :

Page 20: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Design Patterns Application Example: The VM System

• Recall the design class diagram of the VM

+Sendmoneytocustomer()+Sendchangetocustomer()+calculatechangeexactchange()

-attribute1Money Dispenser

+sendproducttocustomer()-attribute1

Product Dispenser

+ShowmessagesonScreen()

CRT Display+ReadoperatorInput()()+SendSignalstoVMCOntroller()

WirelessKeyBoard

+Readcustomerselction()+SendSignaltoVMController()

NumericKeyPad

+getproductID()()+getmoneyammount()()+sendquieries()+receiveresult()+sendresponse()

DatabaseController

+receiveinputsignalfromNumericPad()+RecieveinputsignalsfromWirelessKeyboard()+SendshowmessgaetoCRT()+DisableHWcomponents()+sendCommandtoProductdispense()+SendcommandtoMoneydispenser()+ReceiveMoneyforMoneyDectectorhw()

-NPID-WKB-Moneydectorswitchoff-Money-Productdiableswicthoff-Moneydispenserswitchoff

VmController

-End1*

-End2

*

-End3 *

-End4

*

-End5 *-End6 *

-End7 *

-End8 *

-End9*-End10*

-End11 *

-End12 *

Page 21: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

The State Diagram of the VM Controller

UserMode

MiantenanceMode

Received inputSignal from Wireless Keyboard

Reset

Interact with the User

Interact with the Maintenance Operator

Page 22: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Design Patterns Application Example: The VM System

• The State Pattern Applied to the 2 state VM example

VMContoller

++CreateInitState()Setstate()

<<interface>>VMController State

state

UserMode MaintenanceMode

+UpdateDatabase() +InsertMoney()+SelectProduc()

2Class of Objects

Abstract State Class

Concrete State 1 Class Concrete State 2 Class

Changestate()Deletestate()

Page 23: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Design Patterns Application Example: The VM System

• Applying the state patterns to the VM design class diagram enhanced the design by reducing coupling and increasing cohesion

• Instead of handling all the operations by one VM controller class, these operations were divided on the state classes The UserMode state class and the maintenance Mode state class

• This reduces the coupling between the VM class and interface classes since each interface class would be coupled to one of the state classes instead

• This also increases the cohesion of operations in all classes

Page 24: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Design Patterns Application Example: The VM System

• The Strategy Pattern Applied to the VM example

+context_interface() : void

Maintenance_mode

+Update() : char

Strategy

+Update() : char

Periodic

+Update() : char

When_completed

-End1

1

-End2

*

Page 25: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Design Patterns Application Example: The VM System

• The Strategy Pattern is applied to the maintenance Mode state class to implement two different maintenance startegies

• Periodic Maintenance is done in specific periods in time

• Whereas completed Maintenance is done when products are all finished

Page 26: تحسين تصميم البرمجيات بإستخدام أنماط التصميم  Software Design Refinement Using Design Patterns

Refine Architecture of the VM System

VMControllerPackage

InputPackage

OutputPackage

DatabasePackage