DOC PREVIEW
UIUC CS 598 - Patterns

This preview shows page 1-2-3-4-24-25-26-50-51-52-53 out of 53 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 53 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

PatternsCoding patternsOOD patternsArchitectural PatternsBusiness SoftwarePowerPoint PresentationSlide 7ReplicationPeer-to-peer gamesSlide 10Fault toleranceCroquetPersistenceSummarySmalltalk Coding PatternsThe BookCoding StandardsCoding Standards for SmalltalkNamesIntention Revealing SelectorMethod NamesChange state of receiverChange state of argumentReturn value from receiverSlide 25Accessing MethodsWhen to use Accessing MethodsQuery MethodSlide 29Boolean Property SettingConverter MethodConverter Constructor MethodConstructor MethodSlide 34Constructor Parameter MethodCreation Parameter MethodShortcut Constructor MethodComposed MethodComposed Method UsageMethods from CommentsReversing MethodReversing methodSlide 43Method objectExample of Method ObjectSlide 46Slide 47Slide 48Slide 49Extract methodExecute Around MethodHow to make a good programSlide 53PatternsThings that repeat.Solutions to a problem in a context.Patterns for coding/low-level design / architecture/user interface/problem domainCoding patternsSmalltalk Best Practice PatternsKent BeckPrentice-Hall, 1997OOD patternsDesign Patterns: Elements of Reusable Object-Oriented SoftwareErich Gamma, Richard Helm, Ralph Johnson, John VlissidesAddison Wesley, 1995.Architectural PatternsPattern-Oriented Software ArchitectureF. Buschmann, R. Meunier, H. Rohnert, P.Sommerlad, M. StalWiley, 1996http://www.cs.wustl.edu/~schmidt/POSA/Business SoftwarePatterns of Enterprise Application ArchitectureMartin Fowler et. al.Addison-Wesley, 2002http://www.martinfowler.com/books.html#eaaDomain Driven DesignEric EvansAddison-Wesley, 2004http://domaindrivendesign.org/Patterns“Solution to a problem in a context”Best practice.Things experts doReplicationKeep a copy of data on serveral computers.Every time one computer makes a change, make a change on the replicas, as well.Peer-to-peer gamesGUIModelGUIModeleventseventsbrokerPeer-to-peer gamesEvent-oriented, not object-orientedEasy to convert from single-cpu to distributedEasy to debugEasy if only one person can make a move at onceMust synchronize simultanious movesHard to make secureFault tolerancePrimary and backupMessages go to everyone, only primary respondsIf primary doesn’t respond, backup takes overCroquet3D virtual worldRendering takes place on local machineEvents must be synchronized, then all copies of the world are changedOpencroquet.orgPersistenceKeep everything in memoryReplicate for backupSynchronize with a single lockVery fastNo SQLMust fit in memorySummaryDesign is hardDesign is about tradeoffsThere is no perfect solution, just a solution whose defects don’t bother you.Patterns are no panacea, but fit people.Smalltalk Coding Patternsmostly fromSmalltalk Best Practice PatternsKent BeckPrentice-Hall, 1997The Book1. Introduction (Read2. Patterns (Read3. Behavior (Today4. State (Next time5. Collections (Last week6. Classes (Next time7. Formatting (Next timeCoding StandardsStandardsimprove communicationlet code be the designmake code more habitablechangeCoding Standards for SmalltalkVariables have no typesNames can be any lengthOperations named with keywordsPretty printerNamesNames should mean something.Standard protocolsObject (printOn:, =)Collection (do:, add:, at:put:, size)Standard naming conventionsIntention Revealing SelectorReadability of message send is more important than readability of method.Name should specify what method does, not how.Method NamesIf 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 receiverChange state of receivermethod name is verb phrase- translateBy:- add:Change state of argumentVerb phrase ending with preposition like on or to.- displayOn:- addTo:Return value from receivermethod name is noun phrase or adjective, a description rather than a command- translatedBy:- size- topLeftMethod NamesSpecialized names for specialized purposes.Double-dispatching methodsAccessing methodsQuery methodsBoolean property settingConverter methodsAccessing MethodsMany instance variables have accessing methods, methods for reading and writing them.Accessing methods come in pairs.name, name:width, width:x, x:When to use Accessing MethodsTwo opinions:Always, including an object’s own instance variablelazy initialization, subclassing is easierOnly when you need to use it.better information hidingQuery MethodMethods 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?Query MethodPrefix every query method with "is".isNilisControlWantedisEmptyPut query methods in protocol “testing”Boolean Property SettingDon'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 / beCleanConverter MethodOften 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)Converter Constructor MethodA 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’Constructor MethodClass methods that create instances are in category "instance creation methods".Creation followed by initialization is the most flexible.- Point new x: 0; y: 0Important to preserve invariants and avoid ill-formed objects.Constructor MethodInstance creation methods should create well-formed instances. Pass all required parameters to them.- Point x: 0 y: 0- SortedCollection sortBlock: aBlock- Set newConstructor Parameter MethodHow should a Constructor Method initialize new object?Separate setters are most flexiblex: aNumber y: anotherNumber^self new x: aNumber; y: anotherNumberMust maintain invarients.Creation Parameter MethodProvide 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: anotherNumberShortcut Constructor MethodIt is verbose to keep mentioning class names, and they are duplicated.Point x: width y: heightwidth @ heightComposed MethodHow big should a method be?Write methods that perform one identifiable


View Full Document

UIUC CS 598 - Patterns

Download Patterns
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Patterns and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Patterns 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?