Design pattern

34
Impact of Design Pattern on Software Quality Omar Adnan Isaid

Transcript of Design pattern

Impact of Design Pattern on Software Quality

Omar Adnan Isaid

Agenda

• What is Software Quality ?• What is Design Pattern ?• Gang of Four (GoF).• Design Pattern Elements (Explained by Façade

Design Pattern).• Advantages of Design Patterns.• Strategy Design Pattern (Explained by Duck

Game).• Auto Dynamic Difficulty Framework.

What is Software Quality ?

• ISO 9126: \Software quality characteristic is a set of attributes of a software product by which its quality is described and evaluated".

• German Industry Standard DIN 55350 Part 11: \Quality comprises all characteristics and significant features of a product or an activity which relate to the satisfying of given requirements".

• ANSI Standard (ANSI/ASQC A3/1978): \Quality is the totality of features and characteristics of a product or a service that bears on its ability to satisfy the given needs".

What is Design Pattern?• Design pattern is a solution for a repeatable

problem in the problem design.• A design pattern isn't a finished design that

can be transformed directly into code. • A design pattern is a description or template

for how to solve a problem that can be used in many different situations.

Gang Of Four (GoF)

• GoF are Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides

• GoF are documented 23 classic software design patterns in their book : Design Patterns: Elements of Reusable Object-Oriented Software.

• The GoF book first published at October 1994 and documented design patterns already exist but not documented before.

Design Pattern Elements

Name element

[1] Name: Short ,Comprehensive ,No more than two words.• The meaning of the word Façade in oxford

dictionary "The principal front of building that faces to a street or open space".

• The term Façade strongly related to the goal of the Façade design pattern, which is to provide a unified interface for different subsystems of a system.

Design Pattern Problem

[2] Problem• The suitable situation to apply the design

pattern. • The preconditions must be available before

the designer decides to apply certain design pattern.

• the design pattern can clarify the structure of the inflexible designs of certain problems.

Façade Design Pattern Problem

• Suitable situation : when a unified interface is needed to decouple different subsystems of a complex system.

• Preconditions before apply Façade Design Pattern1. A simple interface can be applied to access different

subsystems of a system.2. The development of the system will provide tightly coupled

system.3. Each subsystem can have an interface, which can be

accessed using Façade design pattern interface.• Inflexible to apply the Façade design pattern if it will act as a

bottleneck and limit the features of the system.

Design Pattern Elements

• [3] Solution • Refers to the description of the problem

solution and the arrangement of the elements.

• The element for the problem’s solution is the class.

Design Pattern Solution

Façade interface

Façade interface can access any subsystems

Advantages Of Design Patterns

[A] The Design patterns document the efforts of the experts , who did their best efforts to provide flexible and reusable software.[B] The Design Pattern concerns with a flexible software architecture.The points [A] & [B] implies a set of advantages for the developers, designers and others.

Advantages Of Design Patterns• The Design Patterns provide a set of

advantages for the developers and designers1. Not to reinvent the wheel.2. Trade off between different solutions for the

same problem(Get the right pattern faster).3. Studying the design patterns improves the

experience and knowledge of novices.

Strategy Design Pattern

• Assume the scenario where a certain game has different types of ducks.

• The ducks in the game are different in their sound and behavior.

• Not all the ducks have the same way of flying or have the same sound.

Duck Hunt! NES 1984

Inheritance Solution

Override subclass methods

Disadvantages of Duck Inheritance

• If the Duck superclass has a lot of subclasses serious disadvantages can be emerged

• For example, if the Duck superclass has 50 subclasses , where each Duck has a different voice and behavior .

• The developer must override 100 methods making some bugs in the road.

• At least some methods for different subclasses may be modified from time to time.

Interface Design

Problems of Interface Design

• The interface design eliminates the overhead of override the frequently changed methods of the superclass Duck.

• If the mallard and red head ducks have the same fly and sound behaviors , then the code of fly and sound methods for the MallardDuck and RedheadDuck classes are duplicated.

• The inheritance design means to modify methods from time to time .But, interface design causes code duplication , which is maintenance problem!

• No code reuse

The Strategy Design Pattern Solution

Take the parts that vary and encapsulate them so that later you

can alter or extend the parts that vary without affecting those that

do not

Interchangeable algorithms

• The Duck behavior (sound or fly) can be described as set of interchangeable algorithm.

• For example the algorithms for the sound behavior can be quack , squeak or mute

• The algorithms are interchangeable because the Duck sound can one of them.

Strategy Design Pattern

Implementing Fly and Sound Algorithms

Advantages of the Strategy Design

• Reusability : Objects can use fly , quack behaviors because these behaviors are not hided anymore in the Duck superclass

• Maintainability : Modify existing behaviors without make any modifications on the subclasses of the Duck superclass

Medal of Strategy Pattern

Pattern Coupling (McNatt et. al,2011)

• The system architecture can be viewed as a set of design patterns connected together.

• The coupled design patterns is a pair of design patterns connected together using common classes.

Types of Coupling

1. Tight Coupling 2. Loose Coupling

Tight Coupling

• The common classes strongly connected the design pattern couple.

• Tight coupling leads to a large block of code.• Any modification in the design pattern couple

can have a serious cost.

Loosely Coupling

• The common classes loosely connect the design pattern couple.

• This type results in a maintainable and reusable design pattern couple.

Overlapping Of Abstract Factory and Visitor Patterns

Auto Dynamic Difficulty Framework

• The ADD is framework to change the game experience to match the player experience.

• The reusing of the ADD design patterns eliminates the waste of cost and time to create the ADD game-by-game