design_patterns_I - CSE 332 Design Patterns Introduction to...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 332: Design Patterns Introduction to Design Patterns • You’ve seen design patterns several times this semester – The Iterator pattern has been discussed in some detail (STL lectures) – We’ve also seen the Factory Method pattern (but haven’t named it yet) • This lecture will focus on design patterns in detail – What they are and how they are structured (in detail) – Introduction to some of important design patterns (from Gamma et al.) • We’ll work through a design exercise step by step – Each time we come to a design problem we’ll introduce a design pattern – We’ll see how the pattern resolves the problem • Next lecture we’ll talk about how to combine sets of patterns – Create “design pattern languages” that also can be reused – Today’s patterns form a pattern language, though we won’t consider them in that way until we’ve reached the end of the design exercise CSE 332: Design Patterns What’s a Design Pattern? • A design pattern has a name – So when someone says “Adapter” you know what they mean – So you can communicate design ideas as a “vocabulary” • A design pattern describes the core of a solution to a recurring design problem – So you don’t have to reinvent known design techniques – So you can benefit from others’ (and your) prior experience • A design pattern is capable of generating many distinct design decisions in different circumstances – So you can apply the pattern repeatedly as appropriate – So you can work through different design problems using it CSE 332: Design Patterns Pattern-Oriented Design • We’ll start by outlining a simple design exercise (Part I) – Idea: maintain a portfolio of stocks and bonds – Design goals • Traverse the portfolio and print out each element • Print out the portfolio in different orders • Provide a common interface to a single portfolio instance • Calculate current and projected values of the portfolio • We’ll see how key patterns drive the design (Part II) – Iterator: access elements sequentially no matter how stored – Factory method: create a related type polymorphically – Singleton: provides access to a single instance – Strategy: makes behaviors pluggable via common interfaces – Adapter: converts an interface you have into one you want – Visitor: allows interaction with heterogeneous collections • We’ll talk about how we’ve evolved a pattern language (Part III) – Can be reused different design settings where the same issues arise CSE 332: Design Patterns Part I: Design Exercise Outline • Idea: keep track of a portfolio of stocks and bonds – Abstractly, both stocks and bonds are securities • Each has a name, a number of shares, a current value, and a projected value – Stocks and bonds are distinct abstractions, however • Stocks can have a dividend that’s paid out periodically • Bonds can earn interest that’s also paid out periodically • Design goals – Traverse the portfolio and print out each element...
View Full Document

{[ snackBarMessage ]}

Page1 / 19

design_patterns_I - CSE 332 Design Patterns Introduction to...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online