patterns and reuse. patterns reuse of analysis and design

Post on 02-Jan-2016

221 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Patterns and Reuse

Patterns

Reuse of Analysis and Design

Patterns

• Patterns describe common ways of doing things.• They are collected by people who spot repeating

themes in designs.• They take each theme and describe it so that

others can use it.• They capture the static and dynamic structures and

collaborations of successful solutions to problems that arise when building applications in a particular domain.

Patterns of Learning

• To be good at chess, you have to:– Know the rules.

– Learn the principles.

– Observe past games that were played (patterns).

• To become a good software engineer you have to:– Know the rules.

– Learn the principles.

– Observe past systems that are written (patterns).

Patterns

• Patterns == problem/solution pairs in a context• They capture the static and dynamic structure and

collaboration among key participants in software design

• They facilitate the reuse of successful software architectures and designs.

Patterns

• A pattern is much more than a model.• It must contain the reason why it is the way

it is.• The pattern must:

– Make the problem clear.– Explain why it solves the problem.– Explain in what circumstances it works.– Explain in what circumstances it does not work.

Design Pattern Descriptions

• Main parts– Name and intent

– Problem and context

– Requirements addressed

– Abstract description of structure and collaborations in solution

– Positive and negative consequences of use

– Implementation guidelines and sample code

– Known uses and related patterns

Design Pattern Descriptions

• Pattern descriptions are often independent of programming language or implementation details.

When to Use Patterns

• All the time.• When trying to develop something in:

– Analysis.– Design.– Coding.– Project management.

• Search for any available patterns that might help you.

Example Problem

• You have objects running in a process on your desktop.

• They need to communicate with other objects running in another process.– (Maybe on your desktop, maybe elsewhere).

• You don’t want the objects in your system to have to worry about finding other objects on the network or executing remote procedure calls.

Solution

• Create a proxy object within your local process for the remote object. – This has the same interface as the remote object.

– Your local objects talk to the proxy using the usual in-process message sends.

– The proxy is responsible for passing any messages on to the real object, wherever it may reside.

• Proxies are a common technique used in networks and elsewhere.

Reusing Experience

• Proxies have been used over and over again. People know:– How they can be used.– Their advantages.– Their limitations.– How to implement them.

• Proxy as a design pattern describes a design technique.

Documenting Patterns

• The general form for documenting patterns is to define items such as: – The motivation or context that this pattern applies to. – Prerequisites that should be satisfied before deciding to

use a pattern. – A description of the program structure that the pattern

will define. – A list of the participants needed to complete a pattern. – Consequences of using the pattern...both positive and

negative. – Examples!

Sample design pattern• In an ordering system, we often see the

following pattern:

StockDocket

Order Line

Customer SupplierStaff

SupplierOrder

SupplierOrderLine

Patterns and Frameworks

• Patterns support reuse of software architecture and design

• Frameworks support reuse of detailed design and code.– A framework is an integrated set of components that

collaborate to provide a reusable architecture for a family of related applications.

• Together, design patterns and frameworks help to – Improve software quality– Reduce development time.

Frameworks

• These are semi-complete applications.– Complete applications are developed by

inheriting from and instantiating parameterised framework components.

• Frameworks provide domain-specific functionality.– e.g. business applications, telecommunication

applications, window systems, databases, distributed applications, OS kernels.

Frameworks

• Exhibit inversion of control at run-time– i.e. the framework determines which objects

and methods to invoke in response to events.– Microsoft Office is a framework.– Note the common patterns that are in use in this

framework.

PowerPoint screen

Word screen

Excel screen

Game framework

• Tic-tac-toe and Chess.

• In both cases:– The game is played by two players– The game is played on a square, squared board.– Players move alternately.– To make a move is to alter the state of the

board by adding, removing and / or moving some tokens, which are things on the board.

– Any token on the board is owned by one or other player.

– All relevant information is available to both players.

– Which moves are legal depends on the state of the board - which tokens are where- possibly together with other factors like the history of the play.

– Who wins depends on the same factors.

Chess game

Tic Tac Toe game

top related