C++ & Design Patterns - Introduction

Why look at design patterns again?

So we can get a more formal and thorough understanding of what we now intuitively know and use.

What is a Design Pattern?
A design pattern names, abstracts and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design.

Represent recurring problems and expert solutions. Allow novice programmers to learn from the experts experience. Lets us discuss and think about in concrete ways what was abstract. Originally applied to building design. At a certain level of abstraction. Help identify and model less obvious abstractions. Helps with object granularity (what should be an object). Helps decide what does and doesn't belong in a class's interface.

Parts of a GOF Design Pattern p.6
* important part.
  1. Pattern Name*: handle used to describe design problem, its solutions and consequences in a word or two. Gives us something to think about.
  2. Pattern Class*: Purpose (Creational, Structural, Behavioral) & Scope(Class, Object)
  3. Intent*: short statement of - What it does, Why it does it, and what problem it addresses. Scannable
  4. Also Known As:
  5. Motivation: A scenario that illustrates a design problem and how the pattern fixes it. Somewhat abstract.Applicability*: Quick list of when to use it. Scannable
  6. Structure*: UML of the class structure or interactions.
  7. Participants*: Names the classes and objects involved. Provides standard names for the various roles in a pattern.
  8. Collaborations: CRCish list of interactions.
  9. Consequences*: What this patterns means to the system it is used in.
  10. Implementation: Tips and traps, variants.
  11. Sample Code
  12. Known Uses: Proves its worthy of being a pattern.
  13. Related Patterns*: Frequently too short list of other patterns and there relationships. Alternative or frequently combined patterns listed here.
How to select a pattern? How to use a pattern? Suggest you read Chapter 2, A Case Study or also Pattern Hatching by Vlissides.

Pattern Parts: Things that make up patterns. Side Note: UML

C++

Allows procedural or OO style. Primitive variables(char, int, bool, float, double etc), declarations, comments and operators (bitwise, logical, trinary) the same as Java. Blocks and functions. Same control constructs as Java (for, while, do while, if, switch, default, break, continue). Differences are that if doesn't require booleans. This allows = errors. Put variable on the right. Also no named break. Instead we have goto. Exception handling basically the same. Has namespaces instead of packages. They are more flexible but not as nice.

Discuss the separation of header and source files. Headers contain declarations while source contains definitions.

The preprocessor:

The extern C linkage convention. on a single declaration or a block

My personal code style for C++. The class example will be a linked list. Not new, but we understand it well, or do we?

jwalker@cs.oberlin.edu