Date post: | 28-Dec-2015 |
Category: |
Documents |
Upload: | austin-griffith |
View: | 317 times |
Download: | 8 times |
Chapter 5Design Principles II:
Flexibility, Reusability, and Efficiency
Process Phase Affected by This ChapterRequirementsAnalysis
Design
Implementation
ArchitectureFramework Detailed Design
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Aspects of Flexibility
… 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 functionality
Example: allow overdrafts
Anticipate …
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Registering Website Members
WebSiteregister()
Member0..nmembers
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Registering Website Members Flexibly
WebSite Member0..n
StandardMemberXMemberYMember
members
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Adding Functionality to an Application: Alternative Situations
Within the scope of …
1. … a list of related functions
Example: add print to an air travel itinerary functions
2. ... an existing base class
Example: add “print road- and ship- to air itinerary ”
3. ... 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.
Adding Functionality When a Base Class Exists
TripprintItinerary()
StandardTripprintItinerary()
SomeApplicationClass
Method(s) callprintItinerary()
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Adding Functionality Through a Base Class
TripprintItinerary()
SeaTripprintItinerary()
SomeApplicationClass
LandTripprintItinerary()
StandardTripprintItinerary()
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Additional Type of Flexibiliy
Flexibility Aspect: ability to … Described in …… create objects in variable configurations determined at runtime
“Creational” design patterns – chapter xx
… create variable trees of objects or other structures at runtime
“Structural” design patterns – chapter xx
… change, recombine, or otherwise capture the mutual behavior of a set of objects
“Behavioral” design patterns – chapter xx
… create and store a possibly complex object of a class.
Component technology – chapter xx
… configure objects of predefined complex classes – or sets of classes – so as to interact in many ways
Component technology – chapter xx
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
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.
Making a Method Re-usable
Specify completelyo Preconditions etc (see figure xx)
Avoid unnecessary coupling with the enclosing classo Make static if feasible
o Include parameterizationo i.e., make the method functional
o But limit the number of parameters
Make the names expressiveo Understandability promotes re-usability
Explain the algorithmo 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.
Making a Class Re-usable
Describe the class completely
Make the class name and functionality
match a real world concept
o See section xx
Define a useful abstraction
o attain broad applicability
Reduce dependencies on other classes
o Elevate dependencies in hierarchy
alternatives
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Reducing Dependency Among Classes
Customer
Replace …
Piano
with …
Customer PianoPianoOrder
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Leveraging Inheritance, Aggregation and Dependency for the Re-use of Class Combinations
CustomercomputeBill()
RegularCustomercomputeBill()
CustomercomputeBill()
Billcompute()
CustomercomputeBill( Orders )
Ordersvalue()
(1) Leveraging inheritance
(3) Leveragingdependency
(2) Leveragingaggregation
CustomercomputeBill()
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Basic Approaches to Time Efficiency
Design for Other Criteria, Then Consider Efficiencyo Design for flexibility, reusability , …
o At some point, identify inefficient places
o Make targeted changes to improve efficiency
Design for Efficiency From the Starto Identify key efficiency requirements up front
o Design for these requirements during all phases
Combine These Two Approacheso Make trade-offs for efficiency requirements during design
o Address remaining efficiency issues after initial design
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Space-Time Trade-offs
Space
Time to process one item
Typical target
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Space-Time-Development Trade-offs
Space Time
Convenience of Development
Limitingacceptable
value
unacceptablevalues
better thanacceptable
values
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Impediments to Speed Efficiency
Loopso while, for, do
Remote operationso Requiring a network
o LAN
o The Internet
Function calls o -- 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.
Trade-off BetweenNumber of Remote Calls and
Volume Retrieved at Each Call
Number of remote accesses
Volume retrieved at each access
Typical target
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Storage Locations
Codebase
RuntimeRAM
Disk storage required at runtime
Disk storage required between runtimes
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Attaining Storage Efficiency
Store only the data needed
o Trades off storage efficiency
vs. time to extract and re-integrate
Compress the data
o Trades off storage efficiency
vs. time to compress and decompress
Store in order of relative frequency
o 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.
Trading off Robustness, Flexibility, Efficiency and Reusability
1A. Extreme Programming Approach
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 -
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Extreme vs. non-Extreme
+ 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 attentionAdapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
A More Flexible Design for Calculator Application
CommandLineCalculator main()
executeAdditions()solicitNumberAccounts()getAnInputFromUser()
interactWithUser()
Existing Design New Design
Calculator solicitNumAccounts()
CalcDisplaydisplay()
CalcOperationexecute()
Add Multiply Divide
Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.
Summary of This Chapter
Flexibility
o == readily changeable
Reusability
o in other applications
Efficiency
o in time
o in space
(These add to Correctness &
Robustness, covered in chapter xx)Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.