1 / 4

Patterns as solutions to problems

Patterns as solutions to problems. A design pattern is the solution to a problem in a context Has a name that helps in remembering/understanding Has forces that describe the situations in which applicable Should supply pros/cons in using the pattern Has a description that summarizes purpose

adonica
Download Presentation

Patterns as solutions to problems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Patterns as solutions to problems • A design pattern is the solution to a problem in a context • Has a name that helps in remembering/understanding • Has forces that describe the situations in which applicable • Should supply pros/cons in using the pattern • Has a description that summarizes purpose • Adapter • You have a class that’s close to what you want, but the interface isn’t quite right, or some functionality is missing • Use an adapter, adapt the existing class to a new interface • Also known as wrapper, similar to Proxy but changes interface/adds functionality

  2. Decorator • Add responsibility to object dynamically, flexible alternative to subclassing for adding functionality • Add responsibility to objects without affecting other objects (transparently) • Remove responsibilities • Extension by subclass impractical (subclass explosion) • Component is the base class • Decorator is a component that contains a component • Used "as-a" component, decorates and forwards

  3. Inheritance and STL in OOLS • Sorter (Comparer) and Filter objects • Appear to use inheritance, virtual operator () • In STL inheritance rarely (never?) works • Template parameters don't support inheritance • Objects often copied/passed-by-value • Solution? Use base-class through decoration by subclass • Base class maintains pointer to "real" sorter • Base class function always used, forwards to virtual • Look at Filter and Sorter base class implementations • How does storing this work?

  4. getopt_long details • #include <getopt.h> works in Eclipse, but requires header file on Unix system • Implementation linked in by –liberty (libiberty.a) • In Eclipse part of standard g++/mingw libraries • See oolsmain.cpp for details on initializing structures and calling function to process options • Notice requirement for short args, could be generated automatically (see header file for struct option) • Switch statement is frought with peril, but liveable • Alternative, map to commands

More Related