Principles of Object-Oriented Software Development
description
Transcript of Principles of Object-Oriented Software Development
![Page 1: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/1.jpg)
Principles of Object-Oriented Software Development
Software Engineering Perspectives
![Page 2: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/2.jpg)
Software Engineering Perspectives
Introduction
Development methods Identifying objects Contracts Towards a formal approach
Summary Q/A Literature
![Page 3: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/3.jpg)
Software Engineering Perspectives
• methods of development
• the identification of objects
• contracts -- refinement
• validation -- a formal approach
Additional keywords and phrases: requirements, analysis,implementation, design as transition, CRC cards,responsibilities, heuristics, contractual obligations, validation
![Page 4: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/4.jpg)
Development methods
Subsections:
Perspectives of modeling Requirements engineering -- Fusion Methods for analysis and design -- a comparative study
![Page 5: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/5.jpg)
Methods
• OOA/D -- incremental [CY91b]
• Objectory -- use-case analysis [Jacobs92]
• OOSA -- model-driven [Kurtz90]
• OOSD -- structured [Wasserman89]
• CRC -- cards [BC89]
• RDD -- responsibility-driven [Wirfs89]
• OMT -- object modeling [Rum91]
• OOD -- development [Booch91]
• Fusion -- lifecycle [Fusion]
![Page 6: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/6.jpg)
Unified Modeling Language
• class diagrams, object interaction, packages, state and activity
standard notation
UML
![Page 7: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/7.jpg)
Structured methods
• structure chart
• process specification
• dataflow diagrams
• hierarchy diagram
• entity-relationship diagrams
• data dictionary
• state transition diagram
tools
![Page 8: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/8.jpg)
Perspectives of modeling
![Page 9: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/9.jpg)
Modeling reality
• requirements -- use cases
• analysis -- domain concepts
• design -- system architecture
• implementation -- language
• support
vernacular
Design model -- system oriented
provides a justification of the architecture
![Page 10: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/10.jpg)
Dimensions of modeling
• object model -- decomposition into objects
• dynamic model -- intra-object state changes
• functional model -- object interaction (data-flow)
OMT
Model of control
procedure-driven, event-driven, concurrent
![Page 11: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/11.jpg)
Model criteria
• unambiguous -- single meaning
• abstract -- no unnecessary detail
• consistent -- absence of conflict
formal approach
![Page 12: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/12.jpg)
Requirements engineering
Fusion
![Page 13: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/13.jpg)
Analysis
• Object Model -- concepts and relations
• LifeCycle Model -- sequences of operations
• Operation Model -- semantics of system operations
Fusion
![Page 14: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/14.jpg)
Design
• Object Interaction Graph -- functional dependencies
• Visibility Graphs -- communication structure
• Class Descriptions -- attributes and methods
• Inheritance Graphs -- subtype refinement
data dictionary
![Page 15: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/15.jpg)
Implementation
• System Lifecycle -- state machines
• Class Descriptions -- coding, performance
validation
![Page 16: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/16.jpg)
Methods for analysis and design
a comparative study
![Page 17: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/17.jpg)
Objectory
• requirements -- use cases, domain object model, user interface
• analysis -- subsystems
• design, implementation -- block model, interaction diagrams
systematic process
![Page 18: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/18.jpg)
OMT
• analysis -- object model, dynamic model, functional model
• design, implementation -- heuristics to implement analysis models
few rules for discovering inconsistencies
![Page 19: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/19.jpg)
Booch
• diagrams -- class, object, timing, state, module, process
descriptive
![Page 20: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/20.jpg)
CRC
• analysis, design -- class, responsibilities, collaborators
exploratory
![Page 21: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/21.jpg)
Formal methods
• operations -- pre- and post-conditions
![Page 22: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/22.jpg)
Comparison as a systematic approach
Objectory OMT Booch CRC Fusion development + +- - x + maintenance + + + - + structure +- +- + + + management + +- +- - + tool support +- +- +- - +
![Page 23: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/23.jpg)
Identifying objects
Subsections:
Modeling heuristics Assigning responsibilities Object roles
![Page 24: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/24.jpg)
Object-Oriented Design -- decomposition into objects
application/system/class oriented
Identifying objects -- responsibilities
data/procedure oriented
Layers of abstraction
components, subsystems, frameworks
![Page 25: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/25.jpg)
Modeling heuristics
Objects -- crisp entities
object = an entity that suffers and requires actions
The method:
[1] Identify the objects and their attributes [2] Identify operations suffered and required [3,4] Establish visibility/interface
![Page 26: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/26.jpg)
Heuristics
model of reality -- balance nouns (objects) and verbs (operations)
Associations
directed action -- drives, instructs communication -- talks-to, tells, instructs ownership -- has, part-of resemblance -- like, is-a others -- works-for, married-to
![Page 27: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/27.jpg)
Candidate classes
• account -- customer's account in the banks database
• atm -- performs financial services for a customer
• cardreader -- reads and validates a customer's card
• cashdispenser -- gives cash to the customer
• screen -- presents text and visual information
• keypad -- the keys a customer can press
• pin -- the authorization code
• transaction -- performs financial services and updates the database
ATM
![Page 28: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/28.jpg)
Eliminating spurious classes
• vague -- system, security-provision, record-keeping
• attribute -- account-data, receipt, cash
• redundant -- user
• irrelevant -- cost
• implementation -- transaction-log, communication
Good classes
our candidate classes
![Page 29: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/29.jpg)
Assigning responsibilities
![Page 30: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/30.jpg)
Object-Oriented Thinking
• Immerse the reader in the object-ness of the material
• Give up global knowledge of control.
• Rely on the local knowledge of objects.
CRC
OO-Design with CRC cards
Class, Responsibility, Collaborators.
![Page 31: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/31.jpg)
Banking modelATM
![Page 32: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/32.jpg)
Interaction classesATM
![Page 33: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/33.jpg)
Object roles and interaction
• actor -- operates (suffers no operations)
• server -- suffers operations
• agent -- suffers and operates ( actor & server)
![Page 34: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/34.jpg)
analyze a little,
design a little,
implement a little,
test a little...
![Page 35: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/35.jpg)
Contracts
Subsections:
Specifying contractual obligations Refining a contract Runtime consistency checking
![Page 36: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/36.jpg)
Contractual obligations
client supplier pre-condition obligation benefit post-condition benefit obligation
![Page 37: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/37.jpg)
Specifying contractual obligations
![Page 38: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/38.jpg)
Assertions
• require -- method call pre-condition
• ensure, promise -- post-condition
• invariant -- object invariance
formal specification
![Page 39: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/39.jpg)
class account { account public: account(); // assert( invariant() ); virtual float balance() { return _balance; }void deposit(float x); to deposit money // require( x >= 0 ); // promise( balance() == old_balance + x && invariant() ); void withdraw(float x); to withdraw money // require( x <= balance() ); // promise( balance() == old_balance - x && invariant() ); bool invariant() { return balance() >= 0; } protected: float _balance; };
![Page 40: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/40.jpg)
System development
• violated pre-condition -- bug in client
• violated post-condition -- bug in supplier
A pre-condition limits the cases thata supplier must handle!
![Page 41: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/41.jpg)
class account { account public: account() { _balance = 0; assert(invariant()); } virtual float balance() { return _balance; } void deposit(float x) { require( x >= 0 ); check precondition hold(); to save the old state _balance += x; promise( balance() == old_balance + x ); promise( invariant() ); }
![Page 42: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/42.jpg)
void withdraw(float x) { require( x <= _balance ); check precondition hold(); to save the old state _balance -= x; promise( balance() == old_balance - x ); promise( invariant() ); } virtual bool invariant() { return balance() >= 0; } protected: float _balance; float old_balance; additional variable
virtual void hold() { old_balance = _balance; } };
![Page 43: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/43.jpg)
Refining a contract
• invariance -- respect the invariants of the base class
• methods -- services may be added or refined
State responsibilities and obligations
Refining a method -- like improving a business contract
class C : public P { virtual void m(); }
pre( m_C ) >= pre(m_P) weaken pre-conditionpost( m_C ) <= post(m_P) strengthen post-condition
![Page 44: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/44.jpg)
class credit_account : public account { credit_account
public: credit_account(float x) { _maxcredit = x; _credit = 0; } float balance() { return _balance + _credit; } float credit(float x) { require( x + _credit <= _maxcredit ); hold(); _credit += x; promise( _credit = old_credit + x ); promise( _balance = old_balance); promise( invariant() ); }
![Page 45: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/45.jpg)
void reduce(float x) { require( 0 <= x && x <= _credit ); hold(); _credit -= x; promise( _credit = old_credit - x ); promise( _balance = old_balance ); promise( invariant() ); } bool invariant() { return _credit <= _maxcredit && account::invariant(); } protected: float _maxcredit, _credit; float old_credit; void hold() { old_credit = _credit; account::hold(); } };
![Page 46: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/46.jpg)
Runtime consistency checking
![Page 47: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/47.jpg)
Assertions -- side-effect free contracts
require -- test on delivery promise -- test during development
Object invariance -- exceptions
invariant -- verify when needed
Global properties -- requirements
interaction protocols -- formal specification
![Page 48: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/48.jpg)
Formal specification -- contracts
type specification -- local properties relational specification -- structural properties, type relations functional specification -- requirements
Verification -- as a design methodology
reasoning about program specification/code
Runtime consistency -- invariance
behavioral types specify test cases invariants and assertions monitor consistency
![Page 49: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/49.jpg)
Summary
![Page 50: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/50.jpg)
Development methods
• Perspectives of modeling
• Requirements engineering -- Fusion
• Methods for analysis and design -- a comparative study
1
![Page 51: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/51.jpg)
Identifying objects
• object-oriented design -- decomposition into objects
• object model -- objects suffer and require
• heuristics -- balance between nouns and verbs
• evaluation -- eliminating spurious classes
• class design -- class, responsibilities and collaborations
2
![Page 52: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/52.jpg)
Contracts
• types -- as an organizing principle
• contracts -- obligations and benefits
• subtyping -- the substitutability requirement
• partial types -- designed to have subtypes
3
![Page 53: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/53.jpg)
Towards a formal approach
• contracts -- formal specification
• verification -- as a design methodology
• runtime consistency -- invariance
4
![Page 54: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/54.jpg)
Questions1.Describe the Fusion method. How does Fusion compare with other methods of OO analysis and design? 2. How would you characterize the differences between functional and object-oriented development methods? 3. Give an outline of the steps required in object-oriented design. What heuristics can you think of for identifying objects? 4. What criteria may be used to eliminate spurious classes from an initial object model? 5. Explain the methods of CRC cards. Give an example. 6. Explain how you may characterize the behavior of an object by means of a contract. 7. What benefits may design by contract have for system developers? And for users? 8. Give a detailed account of the issues that arise in refining a contract. 9. How may contracts be employed to test object behavior. 10. Discuss how a formal approach may contribute to OO software development.
![Page 55: Principles of Object-Oriented Software Development](https://reader036.fdocuments.net/reader036/viewer/2022062518/568146ce550346895db406e9/html5/thumbnails/55.jpg)
Further reading
[Fowler97] is not only a good introduction to UML, but contains also many useful insights on the process of object-oriented development. Additionally, [Fowler97a] may be read as a source on analysis patterns, which are reusable elements of analysis and design. For more information on Fusion, consult [Fusion]. As earlier references on object-oriented methods, I recommend [Booch94], [WWW90] and [Rum91]. Also worthwhile are [Henderson93] and [Champeaux93]. An overview and comparative study of design representation methods is given in [Webster]. [Meyer97] is the ultimate reference on contracts. A more comprehensive article on design by contract is [Meyer92].