Pedagogical and Elementary Patterns Patterns Overview
Total Page:16
File Type:pdf, Size:1020Kb
Pedagogical and Elementary Patterns Overview Patterns Joe Bergin Pace University http://csis.pace.edu/~bergin Thanks to Eugene Wallingford for some material here. Jim (Cope) Coplien also gave advice in the design. 11/26/00 1 11/26/00 2 Patterns--What they DO Where Patterns Came From • Capture Expert Practice • Christopher Alexander --A Pattern Language • Communicate Expertise to Others – Architecture • Solve Common Recurring Problems • Structural Relationships that recur in good spaces • Ward Cunningham, Kent Beck (oopsla ‘87), • Vocabulary of Solutions. Dick Gabriel, Jim Coplien, and others • Bring a set of forces/constraints into • Johnson, Gamma, Helm, and Vlisides (GOF) equilibrium • Structural Relationships that recur in good programs • Work with other patterns 11/26/00 3 11/26/00 4 Patterns Branch Out Patterns--What they ARE • Software Design Patterns (GOF...) •A Thing • Organizational Patterns (XP, SCRUM...) • A Description of a Thing • Telecommunication Patterns (Hub…) • A Description of how to Create the Thing • Pedagogical Patterns •A Solution of a Recurring Problem in a • Elementary Patterns Context – Unfortunately this “definition” is only useful if you already know what patterns are 11/26/00 5 11/26/00 6 Patterns--What they ARE (2) Elements of a Pattern • Structural relationships between •Problem components of a system that brings into • Context equilibrium a set of demands on the system •Forces • A way to generate complex (emergent) •Solution behavior from simple rules • Examples of Use (several) • A way to make the world a better place for humans -- not just developers or teachers... • Consequences and Resulting Context 11/26/00 7 11/26/00 8 Exercise Exercise • Problem: Build a stairway up a castle tower • Problem: Design the intersection of two or • Context: 12th Century Denmark. The region more rural roads is often at war • Context: Denmark • Forces: Confined space. Must be defended • Forces: Low maintenance. Land is cheap. against attack from below. Warriors are Electricity is expensive to deliver. Traffic is mostly right handed. light. Don’t cause an unnecessary stop. • Solution: • Solution: 11/26/00 9 11/26/00 10 Alexander Example Alexander Example (2) • Light On Two Sides of Every Room (159) • Light on Two Sides of Every room: • Major rooms have been placed... •A Thing -- a configuration of rooms with the property • People gravitate to such rooms (converse) • A Description of the Thing -- a picture or • Shadows, glare, softer light gradient... paragraph describing it. • A Description of how to build the thing-- • Locate every room so that it has outdoor Place rooms in the corners of the building. Juxtapose small space adjacent on at least two sides... rooms with large ones. Take care not to destroy the roof layout. Make the windows open onto something beautiful. 11/26/00 11 11/26/00 12 GOF Example Composite(2) • Composite •A Thing -- Panel in Java or (3 * (4 +5)) • Building a complex part-whole hierarchy • A Description of the Thing -- An object in a program that behaves like other objects but which also • Many parts must be composed flexibly contains other objects with that behavior • Tradeoff simplicity and flexibility • A Description of how to build the Thing -- • Structure objects so that a container of Create a class that implements the desired interface. Give the class an instance variable that is a collection of objects components is also itself a component that implement the interface. Implement the methods by delegating to the elements of the collection. 11/26/00 13 11/26/00 14 More Examples Forms for Writing Patterns • Grand- Patterns in Java • Alexandrian – Delegation – See Seminars – Singleton • Outline (sometimes called GOF) –Observer – See Grand – Decorator • Outline is easier and a good place to begin • Alexandrian is more informative and literate 11/26/00 15 11/26/00 16 Alexandrian Form (APL) Modified Alexandrian Form 1. PATTERN NAME* 1. PATTERN NAME* Picture giving architectural example Introduction giving context Introduction giving context *** *** Problem description Problem description Essence of Problem (1-2 sentences) Essence of Problem (1-2 sentences) Body of problem (longest section) Body of problem (longest section) Solution -- Stated in form of an instruction Solution -- Stated in form of an instruction Diagram giving solution graphically Diagram giving solution graphically Examples of use *** *** Resulting context Resulting context 11/26/00 17 11/26/00 18 Patterns--What they are NOT Patterns--What they are NOT (2) • A way to make software cheaper • Just GOF – Instead of software: courses, organizations... • Just OOP • A way to make software faster • Just programming templates • Surprising to experts (mostly) • Just tricks • Invented by their authors • Extra material for students • Just a literary form • New material for students • Stand alone incremental improvements 11/26/00 19 11/26/00 20 Patterns--What they are NOT (3) Overheard • If there is only one way to do something it • Why don’t you just have an immutable isn’t a pattern. (context and forces are key) singleton null object iterator mediate • If it doesn’t properly bring the applicable between your composite decorated facade forces into equilibrium, it isn’t a pattern. and the conoculator valve? • If there is no agreement among experts that • OR-- maybe bridge the flyweight proxy the solution is “best,” it isn’t a pattern. prototype with a factory method mememto adapter? 11/26/00 21 11/26/00 22 Pattern Languages Pattern Languages (2) • Patterns seldom occur alone • Patterns are defined at different time or • Seen properly they are part of pattern space “scale” languages • Patterns at different scale are all of similar • It is the languages that provide the emergent complexity behavior, not the individual patterns • Large scale patterns (towns)as simple as • Context of a pattern is the consequences of small scale (pictures on your wall) one or more other patterns. • Work from large scale down to small within – Patterns are applied in sequence a given context 11/26/00 23 11/26/00 24 Seminars: Fricke/Voelter Seminars 11/26/00 25 11/26/00 26 Seminars Pattern Languages are NOT • Just catalogs of patterns – Patterns in a language work together to solve a complex problem whose parts are solved by the individual patterns. The Goodness and Liveness emerge from the interactions. – In Alexandrian terms, from the spaces defined by the elements in the pattern. Spaces in which humans live. (Architect positions walls but defines spaces between the walls.) 11/26/00 27 11/26/00 28 Patterns Community Wiki Wiki Web • The patterns community tries hard to be • Ward Cunningham maintains a virtual supportive of its members meeting place for all patterns people at • There are many activities that work to this – http://c2.com/cgi/wiki/ end • The Wiki Wiki Web is an interactive web • PLoPs, Lists, Web sites site to which anyone can modify any page. • Patterns Process 11/26/00 29 11/26/00 30 Other Views-Resources More Resources • Brad Appleton’s overview of patterns • Introducing Patterns into Organizations – http://www.enteract.com/~bradapp/docs/patterns-intro.html – Mary Lynn Manns and Linda Rising • More On Christopher Alexander – [email protected] – http://g.oswego.edu/dl/ca/ca/ca.html – Linda is spending this year in Copenhagen • Jim Coplien's Home Page – She is also the author of the Patterns Almanac – http://www.bell-labs.com/~cope/ and the Patterns Handbook • Hillside Group • http://www.cs.unca.edu/~manns/intropatterns.html – http://hillside.net/patterns/ 11/26/00 31 11/26/00 32 Current Key Players Elementary Patterns • Eugene Wallingford • Dwight Duego •Joe Bergin •Zung Nguyen • Robert Duvall • Viera Proulx Overview • Owen Astrachan • Richard Rasala • Alyce Brady • Stephen Wong http://www.cs.uni.edu/~wallingf/patterns/elementary/ •Ed Epp • Javier Galve-Frances (There is a mailing list also) •Rick Mercer • <you> • Doug Dechow • <and you> 11/26/00 33 11/26/00 34 Elementary Patterns Goals • Intended for novices • More effective teaching (not new material) •Both • More effective learning – simpler standard design patterns and – Students can say why they do what they do – Patterns created especially for novices – Students can follow a plan • Varieties of scale, but attacking problems – Students can make connections encountered by novices • Introduction to the patterns way of thinking • Efficiency when solving recurring problems 11/26/00 35 11/26/00 36 Example How to use Elementary Patterns • The Decorator pattern can be used to dynamically add functionality to an object defined by an • Not a syllabus item or exam item interface without modifying the object • Tools for studying design principles • You can use it to develop search strategies in • Tools for reading and organizing programs simple lists/vectors • Tools for writing programs • It is also the basis of the design of the Java I/O libraries • Vocabulary for communication between • Once you understand Decorator, you understand instructor and student Java I/O • Benchmark for evaluating programs 11/26/00 37 11/26/00 38 Tools for reading & organizing Tools for studying design principles programs • Use Decorator or Composite • Enumeration -- Java collections – to show both inheritance and delegation in a • Observer -- Java events way that maximizes the benefits of both • Decorator -- Java I/O – to show dynamic polymorphism • Pipes & Filters -- Compiler passes – to show the power of interface • Immutable -- Making programs simple to understand 11/26/00 39 11/26/00 40 Tools for writing programs