Skip to Content
Design Patterns Explained: A New Perspective on Object-Oriented Design
book

Design Patterns Explained: A New Perspective on Object-Oriented Design

by Alan Shalloway, James R. Trott
July 2001
Beginner to intermediate
368 pages
6h 52m
English
Addison-Wesley Professional
Content preview from Design Patterns Explained: A New Perspective on Object-Oriented Design

Dealing with Changes: Using Functional Decomposition

Look a little closer at the problem of displaying shapes. How can I write the code so that it is easier to handle shifting requirements? Rather than writing one large function, I could make it more modular.

For example, in Step 4c on page 4, where I “Call appropriate function that will display shape, giving it the shape's location,” I could write a module like that shown in Example 1-1.

Example 1-1. Using Modularity to Contain Variation
function: display shape
input: type of shape, description of shape
action:
   switch (type of shape)
      case square: put display function for square here
      case circle: put display function for circle here

Then, when I receive a requirement to be able to display ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design Patterns Explained: A New Perspective on Object-Oriented Design, Second Edition

Design Patterns Explained: A New Perspective on Object-Oriented Design, Second Edition

Alan Shalloway, James R. Trott
Design It!

Design It!

Michael Keeling

Publisher Resources

ISBN: 0201715945Purchase book