4/26/2010

Today • Design Patterns Wednesday • Sample design presentation • “What’s on the test on Friday?”

CSE403 Sp10

David Notkin

Spring 2010

1

Chunking • Advanced chess players are in part superior because they don‟t see each piece individually – Instead, they chunk groups of them together – This reduces the search space they need to assess in deciding on a move • This notion of chunking happens in almost every human endeavor • Such chunking can lead to the use of idioms

CSE403 Sp10

High Level Languages

Design patterns

• High level programming languages can be viewed as providing idioms that have proven generally useful

• “a „well-proven generic scheme‟ for solving a recurring design problem” • Idioms intended to be “simple and elegant solutions to specific problems in object-oriented software design” • A key to design patterns is that they are drawn from examples in existing systems – Not proposed solutions to possible problems, but real solutions to real problems

• Structures – Grouping together heterogeneous elements

• Structured loops – Grouping together disciplined uses of comparisons and branches

• Procedure call – Saving & restoring registers, jumps, …

CSE403 Sp10

3

CSE403 Sp10

2

4

1

4/26/2010

Language independent

Low-level

• They are language-independent – Although some language support is starting to exist in some cases • Again, there is an analogy to high-level control structures – Knuth‟s 1974 article (“Structured Programming with go to Statements”) shows that this is not a language issue alone

• Patterns are a collection of “mini-architectures” that combine structure and behavior • They are closely linked to the programming level

CSE403 Sp10

5

Example: flyweight pattern

CSE403 Sp10

6

An alternative approach

• What happens when you try to represent lots of small elements as full-fledged objects? • It‟s often too expensive • And it‟s pretty common

• Use sharing to support many fine-grained objects efficiently

row

column

a

row

a

CSE403 Sp10

p

row

p

a

column

– Fixed domain of objects – Maybe other constraints

p

row

p

a

row

r

e

n

t

row

r

e

n

a

b

c

d

e

f

g

h

i

j

k

l

n

o

p

q

r

s

t

u

v

w

x

y

m

t

7

CSE403 Sp10

z

8

2

4/26/2010

Flyweight structure FlyweightFactory

Participants • Flyweight (glyph in text example)

Flyweight

GetFlyweight(key)

Operation(extrinsicState)

– Interface through which flyweights can receive and act on extrinsic state

flyweights

• ConcreteFlyweight (character) ConcreteFlyweight

– Implements flyweight interface, shareable, only intrinsic state (independent of context)

UnsharedConcreteFlyweight

Operation(extrinsicState)

Operation(extrinsicState)

intrinsicState

allState

• UnsharedConcreteFlyweight (row, column) • FlyweightFactory – Creates and manages flyweight objects

Client

CSE403 Sp10

9

Sample code class Glyph { public: virtual ~Glyph();virtual void Draw(…); virtual void SetFont(…); … } class Character : public Glyph { Character(char); virtual void Draw(…); private: char _charcode; };

CSE403 Sp10

CSE403 Sp10

10

A little more code • The code itself is in the domain (glyphs, rows, etc.) • But it‟s structured based on the pattern • The client interacts with Glyph, Character

11

Character* GlyphFactory::CreateCharacter(char c) { if (!_character[c]) { _character[c] = new Character(); } return _character[c]; }

• Explicit code for each of the elements in the flyweight structure

CSE403 Sp10

12

3

4/26/2010

Defining a pattern • Name and classification • Intent • Also known as • Motivation • Applicability • Structure • Participants • Collaborations

Classification of patterns • • • • •

• Creational

Consequences Implementation Sample code Known uses Related patterns

CSE403 Sp10

• Original GoF patterns

– Abstract factory, builder, factory method, prototype, singleton

• Structural – Adapter, bridge, composite, decorator, façade, flyweight, proxy

• Behavioral – Chain of responsibility, command, interpreter, iterator, mediator, memento, observer, state, strategy, template method, visitor

13

CSE403 Sp10

An historical aside

A little more

• The Gang of Four loosely based their initial work on that of architect Christopher Alexander – Not a systems or software architect, but an architecture architect (with planning, too) – The Timeless Way trilogy

• Alexander and his influence on CS

14

– www.math.utsa.edu/sphere/salingar/Chris.text.html

• Too much can be (and is) made of the connection to Alexander – In particular, Alexander takes the “big” view of architecture and patterns – In software, it is important but still the “little” view

• The Timeless Way of Building (1979), A Pattern Language: Towns, Buildings, Construction (1977), The Oregon Experiment (1975)

• Not surprisingly, a focus on idiomatic solutions to common design problems

CSE403 Sp10

15

CSE403 Sp10

16

4

4/26/2010

An enlightening experience

The real thing

• I had an experience with two of the Gang of Four • They sat down with Griswold and me to show how to use patterns to (re)design a software design we had published – The rate of communication between these two was unbelievable – Much of it was understandable to us without training (a good sign for a learning curve)

• Design patterns are not a silver bullet • But they are impressive, important and worthy of attention – Some of the patterns have and more will become part and parcel of designers‟ vocabularies – This will improve communication and over time improve the designs we produce – The relatively disciplined structure of the pattern descriptions may be a plus

CSE403 Sp10

CSE403 Sp10

17

Final reminder

18

Questions?

• Design patterns are highly unlikely to be on your mind now • They are lower-level than the design you‟re thinking about at this stage • They are probably elements that each of you, even within a team, can choose to use (or not) on an individual basis • The idea is easy, but there is a learning curve

CSE403 Sp10

19

CSE403 Sp10

20

5

CSE401 Introduction to Compiler Construction

intrinsicState. ConcreteFlyweight. Operation(extrinsicState). allState. UnsharedConcreteFlyweight. CSE403 Sp10. 10. Participants. • Flyweight (glyph in text example). – Interface through which flyweights can receive and act on extrinsic state. • ConcreteFlyweight (character). – Implements flyweight interface, shareable, only.

194KB Sizes 1 Downloads 238 Views

Recommend Documents

Guest lecture for Compiler Construction, Spring 2015
references and (user-defined) exceptions. ✓ modules, signatures, abstract types. The CakeML language. = Standard ML without I/O or functors. The verified machine-code implementation: parsing, type inference, compilation, garbage collection, bignums

Compiler Construction Instructor : Dr. Tiayyba Riaz tiayyba.riaz@cs ...
[email protected]. Fall - 2014. Course Code : CS4435. Credit Hours : 3. Class : BS. Course Description: CS4435 provides the students with an ...

Compiler Construction using Flex and Bison
Most program time is spent in the body of loops so loop optimization can result in significant performance im- provement. Often the induction variable of a for loop is used only within the loop. In this case, the induction variable may be stored in a

Formal Compiler Construction in a Logical ... - Semantic Scholar
Research Initiative (MURI) program administered by the Office of Naval Research. (ONR) under ... address the problem of compiler verification in this paper; our main ...... Science Technical Report 32, AT&T Bell Laboratories, July 1975. Lee89 ...

Formal Compiler Construction in a Logical ... - Semantic Scholar
literate programming), and the complete source code is available online ..... class of atoms into two parts: those that may raise an exception, and those that do not, and ...... PLAN Notices, pages 199–208, Atlanta, Georgia, June 1988. ACM.

Automating the Construction of Compiler Heuristics ...
requirements for the degree of. Doctor of Philosophy of Science in Computer Science and Engineering. Abstract. Compiler writers are expected to create ...

INTRODUCTION TO BUILDING CONSTRUCTION 2008-unprotected ...
holes (ii) drilling bore holes and (iii) Load testing are used. QUESTION 4. A. With the aid of a sketch, show the method of transferring the building line to the ...

Emscripten: An LLVM-to-JavaScript Compiler - GitHub
May 14, 2013 - Emscripten, or (2) Compile a language's entire runtime into ...... html.) • Poppler and FreeType: Poppler12 is an open source. PDF rendering ...

Teaching Compiler Development to Undergraduates ...
large software systems. In this paper, we ... The C- programming language is basically a small trac- ..... on the C- file name and all the C- code is translated to.

Emscripten: An LLVM-to-JavaScript Compiler - GitHub
Apr 6, 2011 - written in languages other than JavaScript on the web: (1). Compile code ... pile that into JavaScript using Emscripten, or (2) Compile a ... detail the methods used in Emscripten to deal with those ..... All the tests were run on a Len

COMPILER DESIGN.pdf
b) Explain the various strategies used for register allocation and assignment. 10. 8. Write short notes on : i) Error recovery in LR parsers. ii) Loops in flow graphs.

Barry's Introduction to Construction of Buildings - Emmitt, Stephen ...
... Project Management. Leeds Metropolitan University. Page 3 of 810. Barry's Introduction to Construction of Buildings - Emmitt, Stephen [SRG].pdf.

eBook Green Construction: An Introduction to a Changing Industry ...
Book sinopsis. What green, sustainable, and high-performance, mean for the construction industry and its workers. Not another how-to book, nor a sermon on the benefits of environmentalism, the text provides an overview of a quickly changing construct

Compiler design.pdf
c) Briefly explain main issues in code generation. 6. ———————. Whoops! There was a problem loading this page. Compiler design.pdf. Compiler design.pdf.