Docsity

HOW DP SOLVES THE PROBLEM, Lecture notes of Design Patterns

Toggle sidebar
bg1
09/09/17 Design Patterns 1
How Design Pattern Solve
Design Problems
1.Finding Appropriate Objects:
• Many objects in design come from the analysis model, but O-O designs
often end up with additional higher-level classes that have no physical
counterparts. Composite pattern can be used to support these high
level abstraction that support flexible designs.
• Objects representing a process or algorithm don’t occur in nature,
yet are an important part of flexible designs. The Strategy pattern
describes how to implement interchangeable families of algorithms.
• State pattern represents each state of an entity as an object. These
objects are typically only discovered late in the course of making
a design more flexible and reusable.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download HOW DP SOLVES THE PROBLEM and more Lecture notes Design Patterns in PDF only on Docsity!

How Design Pattern Solve

Design Problems

1.Finding Appropriate Objects:

  • (^) Many objects in design come from the analysis model, but O-O de often end up with additional higher-level classes that have no phy counterparts. Composite pattern can be used to support these hig level abstraction that support flexible designs.
  • (^) Objects representing a process or algorithm don’t occur in nature, yet are an important part of flexible designs. The Strategy pattern describes how to implement interchangeable families of algorithm
  • (^) State pattern represents each state of an entity as an object. Thes objects are typically only discovered late in the course of making a design more flexible and reusable.

How Design Pattern Solve

Design Problems

2.Determining Object Granularity:

  • (^) Objects can vary tremendously in size and number. They can represent a variety of things, from hardware to entire applications How do we decide what should be an object?
  • (^) Design patterns can help to address this problem. Façade pattern describes how to represent complete subsystems as objects. Flyweight pattern describes how to support huge numbers of object at the finest granularity. Abstract Factory and Builder yields objects whose only responsibiliti are to create other objects. Visitor and Command patterns yield objects whose only responsibili are to implement a request on another object or group of objects

09/09/17 Design Patterns 4

How Design Pattern Solve

Design Problems

4.Specifying Object Implementations:

  • (^) An object’s implementation is defined by its class. An abstract clas is one whose main purpose is to define a common interface for its subclasses. A abstract class is not instantiated.
  • (^) Class versus Interface Inheritance: Class inheritance defines an obj implementation in terms of another object’s implementation. It’s a mechanism for code and implementation sharing. In contrast, inte inheritance (or subtyping) describes when an object can be used in place of another. Many design patterns depend on this distinctio
  • (^) Chain of Responsibility must have a common type, but usually don share a common implementation. In Composite pattern , Componen object defines a common interface, but Composite object often defi common implementation. Command, Observer, State and Strategy often implemented with abstract classes that are pure interfaces.

5.Programming to an Interface, not an Implementa

Two main benefits to manipulating objects solely in terms of the interface defined by abstract classes , as opposed to class inheritance

  • (^) Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that clients expect.
  • (^) Clients remain unaware of the classes that implement these object Clients only know about the abstract class(es) defining the interfac This greatly reduces implementation dependencies between subsyst and leads to the following principle:

Programming to an Interface, not an Implementati

How Design Pattern Solve

Design Problems

Disadvantage of delegation approach, highly parameterized softwa harder to understand than more static software. State, Strategy , and Visitor patterns depend on delegation.

Designing for Change

through Patterns

The key to maximizing reuse lies in anticipating new requirements and changes to existing requirements, and in designing your system so that they can evolve accordingly. Some common causes of redesign and patterns to address them:  1 Creating an object by specifying a class explicitly. Specifying a class name when you create an object commits you to a particular implementation instead of a particular interface. This commitment can complicate future changes. To avoid it, create objects indirectly. Design patterns: Abstract Factory, Factory Method, Prototype.  2 Dependence on specific operations. By avoiding hard-coded requests, you make it easier to change the way a request gets satisfied both at compile-time and at run-time. Design patterns: Chain of Responsibility, Command.

Designing for Change

through Patterns

 6 Tight coupling. Classes that are tightly coupled are hard to reuse in isolation, since they depend on each other. Design patterns: Abstract Factory, Bridge, Chain of Responsibility, Command, Facade, Mediator, Observer. 7 Extending functionality by subclassing. Design patterns: Bridge, Chain of Responsibility, Composite, Decorator, Observer, Strategy. 8 Inability to alter classes conveniently. Design patterns: Adapter, Decorato, Visitor.

How to Select a

Design Patterns

  1. Consider how design patterns solve design problems
  2. Scan Intent sections.
  3. Study how patterns interrelate.
  4. Study patterns of like purpose.
  5. Examine a cause of redesign.
  6. Consider what should be variable in your design.

09/09/17 Design Patterns 13

Designing for Change

through Patterns

Behavioral Chain of Resp. object that can fulfill a request Command when and how a request is fulfilled Interpreter grammar and interpret. of a language Iterator how an aggregate's elements are accessed, traversed Mediator how and which objects interact with each other Memento what private information is stored outside an object, and when Observer number of objects that depend on another object State states of an object Strategy an algorithm Template Method steps of an algorithm Visitor operations that can be applied to object(s) without changing their

09/09/17 Design Patterns 14 How to Use a Design Patterns 1. Read the pattern once through for an overview

  1. Go back and study the Structure, Participants , and Collaborations sections.
  2. Look at the Sample Code section to see a concrete example of the pattern in code
  3. Choose names for pattern participants that are meaningful in the application context
  4. Define the classes.
  5. Define application-specific names for operations in the pattern.
  6. Implement the operations to carry out the responsibilities and collaborations in the