Download presentation
Presentation is loading. Please wait.
Published byRosa Mitchell Modified over 9 years ago
1
Patterns
2
Design comes from Modeling (requirements, analysis, problem) Mending (patch, refactoring) Memory (patterns, recall)
3
Patterns Things that repeat. Solutions to a problem in a context. Patterns for coding/low-level design / architecture/user interface/problem domain
4
Coding patterns Smalltalk Best Practice Patterns Kent Beck Prentice-Hall, 1997
5
OOD patterns Design Patterns: Elements of Reusable Object-Oriented Software Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Addison Wesley, 1995.
6
Architectural Patterns Pattern-Oriented Software Architecture F. Buschmann, R. Meunier, H. Rohnert, P.Sommerlad, M. Stal Wiley, 1996 http://www.cs.wustl.edu/~schmidt/POSA/
7
Business Software Patterns of Enterprise Application Architecture Martin Fowler et. al. Addison-Wesley, 2002 http://www.martinfowler.com/books.html#eaa
8
Domain Driven Design Eric Evans Addison-Wesley, 2004 http://domaindrivendesign.org/
9
Security patterns Munawar Hafiz https://netfiles.uiuc.edu/mhafiz/www/research /patterns/index.htm
10
Replication Keep a copy of data on several computers. Every time one computer makes a change, make a change on the replicas, as well.
11
Peer-to-peer games GUI Model GUI Model events broker
12
Peer-to-peer games Event-oriented, not object-oriented Easy to convert from single-cpu to distributed Easy to debug Easy if only one person can make a move at once Must synchronize simultanious moves Hard to make secure
13
Fault tolerance Primary and backup Messages go to everyone, only primary responds If primary doesn’t respond, backup takes over
14
Croquet 3D virtual world Rendering takes place on local machine Events must be synchronized, then all copies of the world are changed Opencroquet.org
15
Persistence Keep everything in memory Replicate for backup Synchronize with a single lock http://prevayler.org Very fast No SQL Must fit in memory
16
Replication Advantages: Speed – local copy is faster to access Persistence – copy on disk Fault tolerance – backup can respond immediately Disadvantages?
17
Replication Disadvantages: Complexity Can be hard to detect changes If changes can occur in more than one place, must synchronize. Must communicate changes – can reduce response time
18
How to document patterns Motivating example Definition (problem, solution) Worked out examples
19
How to document Get an idea. Look for good example. Write draft. Flesh out with more examples. Get feedback. Improve. Repeat as needed.
20
Pattern Language Patterns that a person or a group uses Christopher Alexander “A Timeless Way of Building” “A Pattern Language” A genetic code for human acts of building
21
Pattern Language Describes set of patterns One pattern leads to another High-level come first, then lower-level Complete set of patterns for a particular problem domain
22
Patterns Help you gain experience, but not a substitute for experience Can be misused - useful for experts to direct Should describe pitfalls, costs
23
Where to find patterns Books Conferences (PLoP, EuroPLoP) Web sites (http://hillside.net)
24
My research in patterns Security patterns with Munawar Hafiz Safety patterns with Lui Sha Parallel programming patterns upcrc.illinois.edu/patterns
25
Summary Design is hard Design is about tradeoffs There is no perfect solution, just a solution whose defects don’t bother you. Patterns are no panacea, but fit people.
26
Smalltalk Coding Patterns mostly from Smalltalk Best Practice Patterns Kent Beck Prentice-Hall, 1997
27
The Book 1. Introduction 2. Patterns 3. Behavior(Today 4. State(Next time 5. Collections 6. Classes 7. Formatting
28
Coding Standards Standards improve communication let code be the design make code more habitable change
29
Coding Standards for Smalltalk Variables have no types Names can be any length Operations named with keywords Pretty printer
30
Names Names should mean something. Standard protocols Object (printOn:, =) Collection (do:, add:, at:put:, size) Standard naming conventions
31
Intention Revealing Selector Readability of message send is more important than readability of method. Name should specify what method does, not how.
32
Method Names If there is already a standard name, use it instead of following these rules. Three kinds of methods change state of receiver change state of argument return value from receiver
33
Change state of receiver method name is verb phrase - translateBy: - add:
34
Change state of argument Verb phrase ending with preposition like on or to. - displayOn: - addTo:
35
Return value from receiver method name is noun phrase or adjective, a description rather than a command - translatedBy: - size - topLeft
36
Method Names Specialized names for specialized purposes. Double-dispatching methods Accessing methods Query methods Boolean property setting Converter methods
37
Accessing Methods Many instance variables have accessing methods, methods for reading and writing them. Accessing methods come in pairs. name, name: width, width: x, x:
38
When to use Accessing Methods Two opinions: Always, including an object’s own instance variable lazy initialization, subclassing is easier Only when you need to use it. better information hiding
39
Query Method Methods that return a value often describe the type of the value because they are noun phrases. Query methods are not noun phrases, but are predicates. How can we make the return type clear?
40
Query Method Prefix every query method with "is". isNil isControlWanted isEmpty Put query methods in protocol “testing”
41
Boolean Property Setting Don't make accessing methods whose only argument is a boolean. Create two methods beginning with ”be". (or “make”) Add "toggle" if necessary. beVisible / beInvisible / toggleVisible beDirty / beClean
42
Converter Method Often you want to return the receiver in a new format. Prepend "as" to the name of the class of object returned. asSet (in Collection) asFloat (in Number) asComposedText (in Text)
43
Converter Constructor Method A class can get cluttered with converter methods that have no relationship with its main responsibility. Make a Constructor Method in the target class that takes the object to be converted as an argument. Date fromString: ‘09/10/01’
44
Constructor Method Class methods that create instances are in category "instance creation methods". Creation followed by initialization is the most flexible. - Point new x: 0; y: 0 Important to preserve invariants and avoid ill-formed objects.
45
Constructor Method Instance creation methods should create well- formed instances. Pass all required parameters to them. - Point x: 0 y: 0 - SortedCollection sortBlock: aBlock - Set new
46
Constructor Parameter Method How should a Constructor Method initialize new object? Separate setters are most flexible x: aNumber y: anotherNumber ^self new x: aNumber; y: anotherNumber Must maintain invarients.
47
Creation Parameter Method Provide a single method that sets all the variables. Preface its name with "set", then the names of the variables. x: aNumber y: anotherNumber ^self new setX: aNumber y: anotherNumber
48
Shortcut Constructor Method It is verbose to keep mentioning class names, and they are duplicated. Point x: width y: height width @ height
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.