Top Banner
PatternsA primer Overview (… Only design patterns?...)
24
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: Patterns Overview

Patterns…

A primer Overview

(… Only design patterns?...)

Page 2: Patterns Overview

Pattern (Classic definition)

• A design pattern is a solution to a general design problem in theform of a set of interacting classes that have to be customized tocreate a specific design.

• Patterns and Pattern Languages are ways to describe best practices,good designs, and capture experience in a way that it is possible forothers to reuse this experience (Hillside Group).

• A Pattern is a way to capture recurring designs in such a way thatothers can readily acquire and use the knowledge and experience(Erich Gamma)

Page 3: Patterns Overview

Christopher Alexander - 1979…

• As an element in the world, each pattern is a relationship betweena certain context, a certain system of forces, which occursrepeatedly in that context, and a certain spatial configuration,which allows these to resolve themselves.

• As an element of language, a pattern is an instruction, whichshows how this spatial configuration can be used, over andover again, to resolve the given system of forces, wherever thecontext makes it relevant.

• The pattern is, in short, at the same time a thing, which happens inthe world, and the rule which tells us how to create that thing,and when we must create it. It is both a process and a thing; both adescription of a thing which is alive, and a description of the processwhich will generate that thing.

Page 4: Patterns Overview

Pressman

• For software design, context allows the reader tounderstand the environment in which the problem residesand what solution might be appropriate within thatenvironment.

• A set of requirements, including limitations andconstraints, acts as a system of forces that influenceshow the problem can be interpreted within its context andhow the solution can be effectively applied.

Page 5: Patterns Overview

Design patterns give us templates!

Pressman, Roger S. Software engineering : a practitioner’s approach, Chapter 12.

Page 6: Patterns Overview

Design patterns are grouped into categories(From Pressman)

• Creational patterns focus on the “creation, composition, and representation” of objects.

• Structural patterns focus on problems and solutionsassociated with how classes and objects are organizedand integrated to build a larger structure.

• Behavioral patterns address problems associated with theassignment of responsibility between objects and themanner in which communication is effected betweenobjects.

Page 7: Patterns Overview

Design patterns are grouped into categories

(From Pressman)

Page 8: Patterns Overview

Design patterns are grouped into categories

Schach, Stephen R. Object-Oriented and Classical Software Engineering

Page 9: Patterns Overview

An example

Sommerville, Ian. SOFTWARE ENGINEERING

Page 10: Patterns Overview

Weaknesses of Design Patterns (From Schach - Object-Oriented and Classical Software Engineering)

1.A major problem is that there is as yet no systematic way to determinewhen and how to apply design patterns.

2.The use of the 23 standard design patterns in a software product may bean indication that the language we are using is not powerful enough.

3.To obtain maximal benefit from design patterns, multiple interactingpatterns are employed. We do not yet have a systematic way ofknowing when and how to use one pattern, let alone multipleinteracting patterns.

4.When performing maintenance on a software product built using theclassical paradigm, it is essentially impossible to retrofit classes andobjects. It is similarly all but impossible to retrofit patterns to an existingsoftware product, whether classical or object oriented.

Retrofitting= addition of new technology or features to older systems

Page 11: Patterns Overview

Strengths of Design Patterns (From Schach - Object-Oriented and Classical Software Engineering)

1.Design patterns promote reuse by solving a generaldesign problem. The reusability of a design pattern can beenhanced by careful incorporation of features that can beused to further enhance reuse, such as inheritance.

2.A design pattern provides high-level documentation of thedesign, because patterns specify design abstractions.

3.Implementations of many design patterns exist. In suchcases, there is no need to code or document those parts of aprogram that implement design patterns. (Testing of thoseparts of the program is still essential, of course.)

Page 12: Patterns Overview

Strengths of Design Patterns (From Schach - Object-Oriented and Classical Software Engineering)

4. If a maintenance programmer is familiar with designpatterns, it will be easier to comprehend a program thatincorporates design patterns, even if he or she has neverseen that specific program before.

5. Research into automated detection of design patterns isstarting to produce results.

Page 13: Patterns Overview

Design in Context (Pressman)

Most representativequestion(systematic way)

Page 14: Patterns Overview

Design in Context (Shalloway & Trott approach)

In Design Patterns Explained (2005), Shalloway, A., and J. Trott suggest thefollowing approach that enables a designer to think in patterns:1. Be sure you understand the big picture—the context in which the

software to be built resides. The requirements model shouldcommunicate this to you.

2. Examining the big picture, extract the patterns that are presentat that level of abstraction.

3. Begin your design with “big picture” patterns that establish a contextor skeleton for further design work.

4. “Work inward from the context” looking for patterns at lowerlevels of abstraction that contribute to the design solution.

5. Repeat steps 1 to 4 until the complete design is fleshed out.6. Refine the design by adapting each pattern to the specifics of the

software you’re trying to build.

Page 15: Patterns Overview

Pattern’s Table (Microsoft & Pressman)

Pressman, Roger S. Software engineering : a practitioner’s approach, Chapter 12.&Microsoft, “Prescriptive Architecture: Integration and Patterns,” MSDN, May 2004, available at http://msdn2.microsoft.com/en-us/library/ms978700.aspx.

Page 16: Patterns Overview

Patterns & Abstraction

• Architecture Patterns.

• Business Patterns,

• Analysis Patterns.

• Data Patterns.

• SOA Patterns.

• UI Patterns.

• Implementation Patterns.

• Process Patterns

• … Tree’ Source: http://aojajena.wordpress.com/tag/abstraction-level/

Page 17: Patterns Overview

Some repositories

• The Hillside Group http://hillside.net/patterns/

• Portland Pattern Repository http://c2.com/ppr/index.html

• Pattern Index http://c2.com/cgi/wiki?PatternIndex

• UI Patterns Collections UI/HCI Patterns http://www.hcipatterns.org/tiki-index.php

• Jennifer Tidwell’s UI patterns www.time-tripper.com/uipatterns/

• Mobile UI Design Patterns http://mobile-patterns.com/

• Pattern Language for UI Design www.maplefish.com/todd/papers/Experiences.html

• UI Design Patterns www.cs.helsinki.fi/u/salaakso/patterns/

Page 18: Patterns Overview

Specialized Design Patterns

• Aircraft Avionics http://g.oswego.edu/dl/acs/acs/acs.html

• Business Information Systems www.objectarchitects.de/arcus/cookbook/

• Distributed Processing www.cs.wustl.edu/~schmidt/

• IBM Patterns for e-Business http://www.ibm.com/developerworks/patterns/

• Yahoo! Design Pattern Library http://developer.yahoo.com/ypatterns/

• MSDN Library patterns & practices

http://msdn.microsoft.com/en-us/library/ff921345.aspx

Page 19: Patterns Overview

Don’t forget the Antipatterns X-(

Whereas patterns describe a recurring problem and its solution, antipatterns describe solutions

that have more negative consequences than positive benefits. In effect, they describe

dysfunctional approaches to problem solving, followed by the changes that should be made to

overcome this dysfunction.Source: Phillip A. Laplante & Colin J. Neill. ANTIPATTERNS - Identification,Refactoring, and Management. CRC Press, 2007.See more in: http://www.antipatterns.com/briefing/index.htm

Page 20: Patterns Overview

Paul Graham on Design Patterns

For example, in the OO world you hear a good deal about“patterns”. I wonder if these patterns are not sometimesevidence of case (c), the human compiler, at work. When Isee patterns in my programs, I consider it a sign oftrouble. The shape of a program should reflect only theproblem it needs to solve. Any other regularity in the codeis a sign, to me at least, that I’m using abstractions thataren’t powerful enough— often that I’m generating by handthe expansions of some macro that I need to write.

Paul Graham http://www.paulgraham.com/icad.html

Page 21: Patterns Overview

For awakening

(From Paolo Ciancarini)

You are enhancing an existing application in a pizza shop.The price of the pizza depends on the options selected bythe user. Each option carries a different additional price.There are a large number of options available (ex: extracheese, type of crust, toppings and so on). Which is thebest pattern for design this context? Why?

Page 22: Patterns Overview

For awakening(From http://www.pm.inf.ethz.ch/education/courses/kse/archive/2011/exercises/DesignPatterns.pdf)

We want to implement a text paragraph. A paragraph is a sequence of lines. Each line is representedby a string. The Paragraph class has to provide at least thefollowing methods:

List<String> alignedText(); // Returns the list of formatted lines in the paragraph.String getLine(int i ); // Returns the line at the ith position .int getCountLines(); // Returns the number of lines in the paragraph.void addLine(String s); // Appends a line to the paragraph.

The formatting algorithm (e.g., left-align or centered) can be selected at runtime. It also has to bepossible to add new formatting algorithms to the program withoutmodifying the Paragraph class.

Your task: Develop a design for Paragraph that satisfies the above requirements.

Which design pattern could you use?

Page 23: Patterns Overview

For awakening(From http://www.pm.inf.ethz.ch/education/courses/kse/archive/2011/exercises/DesignPatterns.pdf)

• We want to extend our design by a character counter. This counter is a separate object that storesthe number of characters in a Paragraph object. Whenever the Paragraph object is changed, thecounter has to be adapted automatically.

Your task: Develop a design for the counter. You are allowed to modify the Paragraph

Which design pattern could you use?

• Also, you must consider the support for Ctrl + Z command, which go back the Paragraph Object tothe previous state (previous content)

Which design pattern could you use?

Page 24: Patterns Overview

Thanks for your [email protected]