A Smalltalk Designs Safari.


83 views
Uploaded on:
Description
A Smalltalk Designs Safari Brian Foote The Refactory, Inc. Why Designs? What's New Here is that Nothing is New Here Examples are about what works Examples give us an approach to discuss what works Examples distil experience Examples give us a succinct outline vocabulary
Transcripts
Slide 1

A Smalltalk Patterns Safari Brian Foote The Refactory, Inc. Smalltalk Patterns Safari

Slide 2

Why Patterns? What’s New Here is that Nothing is New Here Patterns speak the truth what works Patterns give us an approach to discuss what works Patterns distil experience Patterns give us a terse outline vocabulary Smalltalk Patterns Safari

Slide 3

Alexander on Patterns in arrangements originate from examples in issues. "A example is an answer for an issue in a context." "Each example depicts an issue which happens again and again in our surroundings, and afterward portrays the arrangement\'s center to that issue, in a manner that you can utilize this arrangement a million times over, while never doing it the same way twice." Christopher Alexander - A Pattern Language Smalltalk Patterns Safari

Slide 4

Why Patterns in the Wild? Realize where to look Learn how to spot ‘em and perceive ‘em See how they develop Appreciate their history, and our history Understand their biological community and relationship Helps us recognize and find new ones Smalltalk Patterns Safari

Slide 5

The Gang of Four: The Essential Field Guide Design Patterns : Elements of Reusable Object-Oriented Software Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides Addison Wesley, 1995 A point of interest book that changed the way software engineers consider building article arranged projects Smalltalk Patterns Safari

Slide 6

Dr. Johnson, I assume? Incredible pilgrims, as Livingstone and Johnson neither essentially make nor concoct, nor, do they even dependably “discover” Often, their most prominent ability is correspondence... Smalltalk Patterns Safari

Slide 7

Your Guide Over Twenty Years in the Bush... Stalking Smalltalk since ‘81… or ‘85… Patterns? A long-lasting partner of Dr. Johnson... Smalltalk Patterns Safari

Slide 8

Field Guides (cont.) The Design Patterns Smalltalk Companion Alpert, Brown, and Woolf Addison Wesley, 1998 Pattern-Oriented Software Architecture Buschmann, Meunier, Rohnert, Sommerlad, and Stahl Wiley, 1996 The Pattern Languages of Program Design Series Volumes 1-4 Addison Wesley, 1995-2000 Smalltalk Patterns Safari

Slide 9

VisualWorks* The Image: A Virtual Veldt The Cradle of Object-Oriented Architecture An Olduvai Gorge Teeming with Patterns Smalltalk Patterns Safari

Slide 10

GoF Design Patterns Creational examples Abstract Factory Builder Factory Method Prototype Singleton Structural examples Adapter Bridge Composite Decorator Facade Flyweight Proxy Behavioral Patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Strategy Template Method Visitor Smalltalk Patterns Safari

Slide 11

The Big Five Lion Leopard Elephant Buffalo Rhino Composite Proxy Strategy Observer Visitor Smalltalk Patterns Safari

Slide 12

Objects inside of Objects Smalltalk Patterns Safari

Slide 13

Composite Context: Developing OO programming Problem: Complex part-entire progressive system has heaps of comparative classes. Case: archive, part, area, section. Strengths • effortlessness - treat arrangement of parts like a section • power - make new sort of part by making existing ones • security - no unique cases, treat everything the same Smalltalk Patterns Safari

Slide 14

Composite Idea: make conceptual "component" class. Elective 1: each part has a (potentially purge) set of segments. Segment Children Chapter Paragraph ... Issue: numerous parts have no segments Smalltalk Patterns Safari

Slide 15

Composite Component Container Children Leaf Composite and Component have precisely the same. • interface for returning so as to count kids • Component executes Children() unfilled set • interface for including/evacuating youngsters? Smalltalk Patterns Safari

Slide 16

Composite Pattern Component Container Children Leaf Composite and Component have precisely the same. • interface for returning so as to identify kids • Component executes Children() void set • interface for including/uprooting youngsters? Smalltalk Patterns Safari

Slide 17

Two Design Alternatives Component does not comprehend what it is a part of. Segment can be in numerous composite. Segment can be gotten to just through composite. Segment comprehends what it is a part of. Part can be in one and only composite. Part can be gotten to straightforwardly. Smalltalk Patterns Safari

Slide 18

Component Knows its Composite Rules when part knows its single composite. A will be a piece of B if and if B is the composite of A. Copying data is perilous! Issue: how to guarantee that pointers from parts to composite and composite to segments are steady. Smalltalk Patterns Safari

Slide 19

Ensuring Consistency the general population operations on segments and composites are: • Composite can identify parts. • Component knows its compartment. • Add/evacuate a part to/from the composite. The operation to add a part to a composite upgrades the segment\'s holder. There ought to be no other approach to change the holder of a part. Smalltalk does not uphold private techniques. Smalltalk Patterns Safari

Slide 20

Example: Equipment weight | absolute | total := 0. self childrenDo: [:each | complete := all out + each weight]. ^total expense ... FloppyDisk CompositeEq. Smalltalk Patterns Safari

Slide 21

VisualComponent>>add: Smalltalk Patterns Safari

Slide 22

Composite Pattern in VisualWorks VisualComponent Children Most operations in CompositePart essentially emphasize over the youngsters and rehash the operation on them. VisualPart ComposedText Container CompositePart ListView Smalltalk Patterns Safari

Slide 23

CompositePart addComponent: aVisualComponent self isOpen ifTrue: [ ... ] ifFalse: [components addLast: aVisualComponent. aVisualComponent holder: self] displayOn: aGraphicsContext "Display each of the recipient\'s components." | clipBox | clipBox := aGraphicsContext clippingBounds. segments do: [:component | (component crosses: clipBox) ifTrue: [component displayOn: aGraphicsContext copy]] Smalltalk Patterns Safari

Slide 24

Summary of Composite is a sort of Component Permits self-assertive chains of importance Add/expel Component from Composite Operations on Composite repeat over Components Smalltalk Patterns Safari

Slide 25

Template Method As ample as sawgrass... Regularly connected with scroungers e.g. printOn: aString Smalltalk Patterns Safari

Slide 26

Factory Method Plentiful in the picture... View defaultControllerClass UILookPolicy XxxClass routines Smalltalk Patterns Safari

Slide 27

Abstract Factory Smalltalk Patterns Safari

Slide 28

Builder ClassBuilder UI Builders Smalltalk Patterns Safari

Slide 29

Prototype This isn’t Self, all things considered... VisualWorks TextAttributes Look for duplicate Thinglab, Morphic... Smalltalk Patterns Safari

Slide 30

Singleton All the Metaclasses... ProcessScheduler SourceFileManager genuine, false, nil Smalltalk Patterns Safari

Slide 31

Strategy Sundry Policies... Smalltalk Patterns Safari

Slide 32

Observer Pattern Intent: Define an one-to-numerous reliance between items so that when one article changes express, every one of its wards are informed and redesigned consequently. eyewitness/subordinate Observer Update Subject AddDependent RemoveDependent Changed LineFigure Update endPoint RectangleFigure Smalltalk Patterns Safari

Slide 33

Iterator Provide an approach to get to the components of a total question successively without uncovering its hidden execution. Iterator Aggregate First() Next() IsDone() CurrentItem() CreateIterator() ConcreteAggregate ConcreteIterator CreateIterator() Smalltalk Patterns Safari

Slide 34

Iterator in Smalltalk 1) Internal iterator - emphasize inside the Iterator simple to utilize, not as capable as outside iterator functions admirably in light of pieces representatives do: [:each | every name printOn: aStream] 2) Combine Next() and CurrentItem() (Smalltalk Stream) employeeStream := GeneralMotors employeeStream. [employeeStream atEnd] whileFalse: [employeeStream next name printOn: aStream] Smalltalk Patterns Safari

Slide 35

Proxy Provide a surrogate or placeholder for another article to control access to it speak to an item in a remote location space make extravagant articles on interest check access rights Proxy has same interface as “real subject”, and advances operations to it Smalltalk Patterns Safari

Slide 36

Proxy Subject Client ask for ... realSubject Proxy RealSubject solicitation demand realSubject ask for Smalltalk Patterns Safari

Slide 37

Proxy Remote intermediary - first bundle contentions, then make remote method call. Virtual intermediary - figure objects, then forward solicitation. Assurance intermediary - check access rights, then forward solicitation. Smalltalk Patterns Safari

Slide 38

Creating an Orphan nil subclass: #Future instanceVariableNames: ‘semaphore " classVariableNames: ‘ " poolDictionaries: " category: ‘Reflection-Examples’ In VisualWorks, ClassBuilder does the rest. Default executions of doesNotUnderstand : and class are given. Smalltalk Patterns Safari

Slide 39

Locating Orphans allBehaviorsDo: aBlock "Evaluate the contention, aBlock, for every sort of Behavior in the system (that is, Object and its subclasses, plus different classes that have no superclass)." Class rootsOfTheWorld do: [:cls | aBlock esteem: cls. cls allSubclassesDo: aBlock] Smalltalk Patterns Safari

Slide 40

Terminology and Taxonomy Is this a Wildebeest? A Gnu ? Class: Mammalia Ord

Recommended
View more...