12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 1.3 Design Patterns 13<strong>Data</strong> TypeADT:• Type• Operations<strong>Data</strong> Items:Logical Form<strong>Data</strong> Structure:• S<strong>to</strong>rage Space• Subroutines<strong>Data</strong> Items:Physical FormFigure 1.1 The relationship between data items, abstract data types, <strong>and</strong> datastructures. The ADT defines the logical form of the data type. The data structureimplements the physical form of the data type.designers learn <strong>and</strong> reuse various techniques for combining software components.Such techniques are sometimes referred <strong>to</strong> as design patterns.A design pattern embodies <strong>and</strong> generalizes important design concepts for arecurring problem. A primary goal of design patterns is <strong>to</strong> quickly transfer theknowledge gained by expert designers <strong>to</strong> newer programmers. Another goal is <strong>to</strong>allow for efficient communication between programmers. Its much easier <strong>to</strong> discussa design issue when you share a vocabulary relevant <strong>to</strong> the <strong>to</strong>pic.Specific design patterns emerge from the discovery that a particular designproblem appears repeatedly in many contexts. They are meant <strong>to</strong> solve real problems.Design patterns are a bit like generics: They describe the structure for adesign solution, with the details filled in for any given problem. Design patternsare a bit like data structures: Each one provides costs <strong>and</strong> benefits, which impliesthat tradeoffs are possible. Therefore, a given design pattern might have variationson its application <strong>to</strong> match the various tradeoffs inherent in a given situation.The rest of this section introduces a few simple design patterns that are usedlater in the book.1.3.1 FlyweightThe Flyweight design pattern is meant <strong>to</strong> solve the following problem. You havean application with many objects. Some of these objects are identical in the informationthat they contain, <strong>and</strong> the role that they play. But they must be reachedfrom various places, <strong>and</strong> conceptually they really are distinct objects. Because somuch information is shared, we would like <strong>to</strong> take advantage of the opportunity <strong>to</strong>reduce memory cost by sharing space. An example comes from representing the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!