Chapter 5 Design Principles II: Flexibility, Reusability, and Efficiency - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Chapter 5 Design Principles II: Flexibility, Reusability, and Efficiency

Description:

Example: add print to the set of existing air travel itinerary functions ... Example: add 'print itineraries for combinations of air, road and ship transportation' ... – PowerPoint PPT presentation

Number of Views:301
Avg rating:3.0/5.0
Slides: 29
Provided by: ericb56
Category:

less

Transcript and Presenter's Notes

Title: Chapter 5 Design Principles II: Flexibility, Reusability, and Efficiency


1
Chapter 5Design Principles IIFlexibility,
Reusability, and Efficiency
2
Ch.5 Design Principles II
  • Flexibility
  • Reusability
  • Efficiency
  • Trade-offs Among the Design Principles

3
5.1 Flexibility
4
Aspects of Flexibility
Anticipate
  • adding more of the same kind of functionality
  • Example (banking application) handle more kinds
    of accounts without having to change the existing
    design or code
  • adding different functionality
  • Example add withdraw function to existing
    deposit functionality
  • changing the overall intended functionality
  • Example allow overdrafts

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
5
Adding More of the Same Kind Registering
Website Members Flexibly
0..n
members
WebSite register()
Approach 1
Member
0..n
members
WebSite
Member
Approach 2 (Adding Flexibility)
StandardMember
XMember
YMember
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
6
Adding Different Functionality Alternative
Situations
  • Within the scope of
  • a list of related functions
  • Example add print to the set of existing air
    travel itinerary functions
  • ... an existing base class
  • Example add print road- and ship- to air
    itinerary
  • ... neither
  • Example add print itineraries for combinations
    of air, road and ship transportation

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
7
Adding Functionality When a Base Class Exists
Trip printItinerary()
SomeApplicationClass
StandardTrip printItinerary()
Makes a method call printItinerary()
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
8
Adding Functionality Through a Base Class
Trip printItinerary()
SomeApplicationClass
SeaTrip printItinerary()
LandTrip printItinerary()
StandardTrip printItinerary()
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
9
Additional Types of Flexibiliy
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
10
Key Concept ? Flexibility ?
We design flexibly, introducing parts, because
change and reuse are likely.
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
11
5.2 Reusability
12
Making a Method Re-usable
  • Specify completely
  • Preconditions, etc
  • Avoid unnecessary coupling with the enclosing
    class
  • Consider making it static, if appropriate, to
    make it more independent of the instance
    variables
  • Include parameterization
  • i.e., make the method functional
  • But limit the number of parameters
  • Make the names expressive
  • Understandability promotes re-usability
  • Explain the algorithm
  • Re-users need to know how the algorithm works

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
13
Making a Class Re-usable
  • Describe the class completely
  • Make the class name and functionality match a
    real world concept
  • Define a useful abstraction
  • Attain broad applicability
  • Reduce dependencies on other classes
  • Elevate dependencies in hierarchy

alternatives
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
14
Reducing Dependency Among Classes
Piano aggregates Customer
Replace
Customer
Piano
PianoOrder aggregates Customer and Piano
with
Customer
Piano
PianoOrder
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
15
Leveraging Inheritance, Aggregation and
Dependency for the Re-use of Class Combinations
Customer computeBill()
(1) Leveraging inheritance
RegularCustomer computeBill()
Customer computeBill()
(2) Leveraging aggregation
Customer computeBill()
Bill compute()
(3) Leveraging dependency
Customer computeBill( Orders )
Orders value()
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
16
5.3 Efficiency
17
Basic Approaches to Time Efficiency
  • Design for Other Criteria, Then Consider
    Efficiency
  • Design for flexibility, reusability ,
  • At some point, identify inefficient places
  • Make targeted changes to improve efficiency
  • Design for Efficiency From the Start
  • Identify key efficiency requirements up front
  • Design for these requirements during all phases
  • Combine These Two Approaches
  • Make trade-offs for efficiency requirements
    during design
  • Address remaining efficiency issues after initial
    design

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
18
Space-Time Trade-offs
Time to process one item
Typical target
Time
Space
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
19
Space-Time-Development Trade-offs
Ease of Development Effort
unacceptable values
Limiting acceptable value
better than acceptable values
Space
Time
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
20
Impediments to Speed Efficiency
  • Loops
  • while, for, do
  • Remote operations
  • Requiring a network
  • LAN
  • The Internet
  • Function calls
  • -- if the function called results in the above
  • Object creation

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
21
Trade-off BetweenNumber of Remote Calls
andVolume Retrieved at Each Call
Volume retrieved at each access
Typical target
Number of remote accesses
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
22
Storage Locations
Runtime RAM
Code base
Disk storage required at runtime
Compress disk storage required between runtimes
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
23
Attaining Storage Efficiency
  • Store only the data needed
  • Trades off storage efficiency vs. time to
    extract and re-integrate
  • Compress the data
  • Trades off storage efficiency vs. time to
    compress and decompress
  • Store in order of relative frequency
  • Trades off storage efficiency vs. time to
    determine location

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
24
5.4 Trade-Offs Among the Design Principles
25
Trading off Robustness, Flexibility, Efficiency
and Reusability
  • 1A. Extreme Programming Approach (See next
    slide)
  • Design for sufficiency only
  • 1B. Flexibility-driven Approach
  • Design for extensive future requirements
  • Reuse usually a by-product
  • 2. Ensure robustness
  • 3. Provide enough efficiency
  • Compromise re-use etc. as necessary to
  • attain efficiency requirements

- or -
Note You dont do trade-offs for correctness
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
26
Pros and Cons Extreme Design vs.
non-Extreme Design
  • Job done faster
  • (usually)
  • Scope clear
  • More likely to be efficient
  • -----------------------------
  • - Future applications less likely to use the work
  • - Refactoring for expanded requirements can be
    expensive
  • Future applications more likely to use parts
  • Accommodates changes in requirements
  • -----------------------------
  • - Scope less clear
  • - Potential to waste effort
  • - Efficiency requires more special attention

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
27
A More Flexible Design for Calculator Application
New Design
Existing Design
Calculator solicitNumAccounts()
CalcDisplay display()
CommandLineCalculator main() executeAdditions() s
olicitNumberAccounts() getAnInputFromUser() intera
ctWithUser()
CalcOperation execute()
Add
Multiply
Divide
Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
28
Summary of This Chapter
  • Flexibility
  • readily changeable
  • Reusability
  • in usage by other applications
  • Efficiency
  • in time
  • in space
  • (Combine these with Correctness Robustness from
    Chapter 4)

Adapted from Software Design From Programming to
Architecture by Eric J. Braude (Wiley 2003), with
permission.
Write a Comment
User Comments (0)
About PowerShow.com