0% found this document useful (0 votes)
860 views

Solving Design Problems With Design Patterns

The document discusses several key aspects of solving design problems with design patterns: 1) It outlines steps for object-oriented design such as finding appropriate objects, determining object granularity, and specifying object interfaces. 2) It explains how design patterns can help with these steps, for example the Strategy pattern helps implement families of algorithms. 3) The document also discusses how design patterns allow systems to be more robust to changes, such as the Abstract Factory pattern which avoids hardcoding object implementations.

Uploaded by

Dhanwanth JP
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
860 views

Solving Design Problems With Design Patterns

The document discusses several key aspects of solving design problems with design patterns: 1) It outlines steps for object-oriented design such as finding appropriate objects, determining object granularity, and specifying object interfaces. 2) It explains how design patterns can help with these steps, for example the Strategy pattern helps implement families of algorithms. 3) The document also discusses how design patterns allow systems to be more robust to changes, such as the Abstract Factory pattern which avoids hardcoding object implementations.

Uploaded by

Dhanwanth JP
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Solving Design Problems with Design Patterns

a) Finding Appropriate Objects


b) Determining Object Granularity
c) Specifying Object Interfaces
d) Specifying Object Implementations
e) Class versus Interface Inheritance
f) Programming to an Interface, not an Implementation
g) Putting Reuse Mechanisms to Work
Inheritance versus Composition Delegation
Inheritance versus Parameterized Types
h) Relating Run-Time and Compile Time Structures
i) Designing for Change
j) Application Programs
k) Toolkits
l) Frameworks
Finding Appropriate Objects

• Object-oriented programs are made up of objects. The hard


part about object-oriented design is decomposing a system
into objects. Design patterns can help in this process by
identifying less obvious abstractions and the objects that
capture them.
• For example, objects that represent a process or algorithm
don’t occur in nature, but they can be crucial in a flexible
design. The Strategy pattern describes how to implement
families of algorithms to solve a particular problem. Those
algorithms can be interchanged at run-time, since they are
objects now and are subject to polymorphism for example.
Determining Object Granularity

• Usually, objects vary in size and number. They can


represent everything down to the hardware or all the
way up to entire applications.
• Design patterns can help to determine proper object
granularity. For example, the Facade pattern describes
how to represent complete subsystems as objects, and
the Flyweight pattern describes how to support huge
numbers of objects at the finest granularities.
• A number of other patterns, such as Composite, describe
how to decompose an object into smaller objects.
Specifying Object Interfaces

• Design patterns help programmers to define interfaces by


identifying their key elements and the kind of data that get
sent across an interface. A design pattern can also tell what
not to put in the interface.
• For example, the Memento pattern describes how to
encapsulate and save the internal state of an object so that
the object can be restored to that state later. The pattern
stipulates that Memento objects must define two interfaces:
• A restricted one that lets clients hold and copy mementos
• A privileged one that only the original objects can use to
store and retrieve state in the memento.
Designing for Change

• Designing a system that is robust to changes is a rather hard task to do. However, a
design that doesn’t take changes into account risks major redesigns in the future.
Design patterns can ensure that a system can change in specific ways.
• Each design pattern lets some aspect of the system structure vary independently of
other aspects, thereby making a system more robust to a particular kind of change.
• Let us look on some examples:
• Creating an object by specifying a class explicitly commits to a particular
implementation instead of a particular interface. That means if we in the future want to
change the object that we use we need also to implement the client code again. On the
other hand using the design patterns, such as Abstract Factory pattern lets you avoid
this problem.
• Dependence on hardware and software platform. Clients that know how an object is
represented, stored, located, or implemented might need to be changed when the
object changes. Hiding this information from clients keeps changes from cascading. An
example is again Abstract Factory used to create different look-and-feel components
across different operating systems.
Guidelines for selecting a design
pattern

i) Consider how design patterns solve design problems


ii) Scan Intent sections
iii) Study how patterns interact
iv) Study patterns of like purpose
v) Examine a cause of redesign
vi) Consider what should be variable in your design
Guidelines for using design patterns
i) Read the pattern once through for an overview
ii) Go back and study the structure, participants and collaborations
sections
iii) Look at the sample code section to see a concrete example of
the pattern in code
iv) Choose names for pattern participants that are meaningful in
the application context
v) Define the classes
vi) Define application-specific names for operations in the pattern
viii) Implement the operation to carry out the responsibilities and
collaborations in the pattern
Some Advantages of Design Patterns

• Common Design Vocabulary


• Computer scientists and programmers create names for algorithms and data
structures. Similarly, design patterns should provide a common vocabulary for
designers. Such vocabulary can be used to communicate, document and
explore design decisions.
• Design patterns make a system less complex, since we can talk about it in the
terms form different design patterns rather then in terms of programming
languages.
• A Documentation Aid
• Describing a system by applying a common design vocabulary makes this
system easier to understand. Having such a common vocabulary means you
don’t have to describe the whole design pattern; programmers just can name it
and expect that the reader already knows what a specific pattern means.
Therefore, writing the documentation can become much more interesting and
easier.

You might also like