object-oriented design csci 5801: software engineering
TRANSCRIPT
![Page 1: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/1.jpg)
Object-oriented Design
CSCI 5801: Software Engineering
![Page 2: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/2.jpg)
Object-oriened Design
![Page 3: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/3.jpg)
Program Design
• Given a system architecture, the program design specifies:– Components, packages, classes and class
hierarchies– Interfaces and protocols between them– The basic algorithms, data structures, security
mechanisms, operational procedures, etc. that each will use
• If the program design is done properly, implementation can proceed directly from it
![Page 4: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/4.jpg)
Design Documentation
• Diagrams: – Basic information about packages and classes
(name, data contained, basic role)– Relationships to other packages/classes
• Specifications:– Application Programming Interface: Detailed list
of functions/method prototypes – Basic algorithm/UI design to meet non-functional
requirements
![Page 5: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/5.jpg)
Object-oriented Programming
• Object = Data + Code to manipulate that data– Data-driven decomposition– Well-defined interfaces in terms of methods
• Objects are instances of a class which defines– Data type (member variables) stored in object– Methods to allow user to manipulate that data– Constructors that define how objects initialized– Can implement interfaces (validated by compiler)
• Package is set of related classes (like a library)
![Page 6: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/6.jpg)
Object-oriented Programming
• OOP commonly used for large-scale programming– Don’t have to know how other components implemented– Just need to know how to use methods at interface
“Client programmer”:
Programmer who uses class in their own code
Methods tomanipulate
state of object
Current stateof object
Object
Only has to understand how to call methods, not how they work
Do not have to understand internal representation of object state
![Page 7: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/7.jpg)
UML for Classes
• Abstract description of class
Data stored in objects of this class
Prototypes of methods this class implement at interface
Abstract description of what class does in terms of the goal of the system
![Page 8: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/8.jpg)
UML for Classes
• Example: Roster class (in Registration package)
![Page 9: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/9.jpg)
Relational UML for Classes
• Used to show relationships between classes– Composition
• One class contains an instance of another as a member variable
– Association• Objects that communicate with one another
– Generalization• One class extends another via inheritance
– Implements• Implements interface used by other component
![Page 10: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/10.jpg)
Composition Relationship
• One class composed of others as member variables
• Can give number of entities aggregate type contains– Can be range (1..4)– * any number from 0 to ∞
+ any number from 1 to ∞
![Page 11: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/11.jpg)
Association Relationship
• Objects communicate via some defined relationship (other than composition)
• Can show complex data types passed for communication
![Page 12: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/12.jpg)
Generalization Relationship
• Subclasses extend a superclass– Inherit all member variables, methods– Can add variables, add/override methods
– Superclass can be abstract• Only exists to be extended to actual subclasses
![Page 13: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/13.jpg)
Interface Relationship
• Class calls methods specified in interface another class implements
![Page 14: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/14.jpg)
UML Example
![Page 15: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/15.jpg)
Design Documentation
• No standard form for design documentation• However, it often contains at global level:
– Overall architecture (in UML)– Sequence diagrams for major processes showing flow
between major components– Data dictionary for major components of system– User interface descriptions, database layouts…
• At package level:– APIs for major classes
• Non-functional constraints on package• Traceability to requirements
![Page 16: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/16.jpg)
Design Documentation
• No standard form for design documentation• However, it often contains at global level:
– Overall architecture (in UML)– Sequence diagrams for major processes showing flow
between major components– Data dictionary for major components of system
• At package level:– APIs for major classes
• Non-functional constraints on package• Traceability to requirements
![Page 17: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/17.jpg)
Sample Sequence Diagram
![Page 18: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/18.jpg)
Example Data Dictionary (ATM)Major System Components• Account: Data control object storing information about current user• LoginInterface: User interface object for ID and PIN entry• LoginLogic: Business logic object to check ID and PIN correctness• PinDatabase: Data interface object to interact with PIN database• PinInterface: User interface to allow administrators to reset PINs• WithdrawInterface: User interface object to allow withdrawals• WithdrawLogic: Business logic object to validate withdrawals• AccountDatabase: Data interface object to account databaseActors• User: Person logged into system to make withdrawals• Administrator: Bank employee authorized to reset PINs• PIN Database: Database of account IDs and corresponding PINs• Account Database: Database of account information
![Page 19: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/19.jpg)
UI Description (ATM Withdrawal)Description:• Provides controls to allow a user to choose an account type to withdraw from,
and an amount to withdraw. It displays messages in case of errors.Usability:• The interface must prevent illegal choices where possible. This is accomplished
by only showing existing accounts and limiting inputs to digits.Visual Appearance and Controls:• Account Selector
– Type: Drop-down list– Use: Allows user to select account to withdraw from (currently either checking,
savings, or credit card).– Initial state: “Please select”– Constraints: Account types not held by user will be disabled
![Page 20: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/20.jpg)
UI Description (ATM Withdrawal)• Amount Entry
– Type: Text box– Use: allows user to enter withdrawal amount– Initial state: Empty– Constraints: Only accepts digits
• Withdrawal Button – Type: Button– Use: Pressed by user to perform withdrawal – Event handling:
• Validates the user has chosen an account type and input a numeric value• Calls methods in WithdrawalLogic to perform withdrawal• Displays pop-up messages if information entered invalid.
• Exit Button – Type: Button– Use: Pressed by user to exit process– Event handling: Destroys this object and constructs a new LoginInterface object.
![Page 21: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/21.jpg)
Database Descriptor Example (ATM)
Account Database StructureField Name Field Type Description
AccountNumber Text (15 characters) Primary key, shared with other tables
HasSavings Yes/No Does this customer have a savings account?
SavingsBalance Number(must be positive)
Amount in savings account
HasChecking Yes/No Does this customer have a checking account?
CheckingBalance Number(must be positive)
Amount in checking account
HasCredit Yes/No Does this customer have a credit account?
CreditBalance Number(must not be negative)
Current credit balance
CreditLimit Number(must be positive)
Credit limit
CreditWithdrawalLimit
Number(must be positive)
Maximum credit withdrawal amount
![Page 22: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/22.jpg)
Application Program Interface
• Prototypes of class methods– Parameters and return types– Any exceptions thrown– Abstract description of
method
• Abstract description of class– Purpose in context of system– Types of information stored– Examples of use…
Everything another programmer needs to know to use the class
![Page 23: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/23.jpg)
API ExampleA Roster stores all students in a section of a course. Users have the ability to add and remove students, and to get a list of all student objects stored in the Roster. Users may not add the same Student object multiple times, or exceed the maximum size of the Roster (set in the constructor). Internally, students are sorted by ID to allow faster search. This class is traceable to the Add Course and the View Students scenariosConstructorpublic Roster (int maxSize)Methodspublic void AddStudent(Student s)public void deleteStudent(String id)public Student[] getRoster()public booolean isOpen()public String serialize()public void deserialize(String s)
![Page 24: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/24.jpg)
API Examplepublic void addStudent(Student s)This method adds the Student object to the roster. It throws a AlreadyInException if the student is already in the roster, or a SectionClosed exception if the number of students is equal to the size set in the constructor (users should check this with isOpen() first).
public void deleteStudent(String id)This method removes the student with the given id from the roster. A NoSuchStudent exception is thrown if a student with that id cannot be found.
![Page 25: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/25.jpg)
Object-oriented Design
• Identify the objects– What are the major nouns used in the description
of the system and its scenarios?
• Determine their attributes and services– What verbs are associated with those nouns?
• Determine the relationships between objects– What other nouns are mentioned in the same or
related sentences?
![Page 26: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/26.jpg)
Example Problem
Design the software to support the operation of a public library. The system has a number of stations for customer transactions. These stations are operated by library employees. When a book is borrowed, the identification card of the client is read. Next, the station’s bar code reader reads the book’s code. When a book is returned, the identification card isnot needed and only the book’s code needs to be read.
SE, Design, Hans van Vliet, ©2008 26
![Page 27: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/27.jpg)
Candidate objects
• software• library• system• station• customer• transaction
27
• book• library employee• identification card• client• bar code reader• book’s code
![Page 28: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/28.jpg)
Carefully consider candidate list
• Eliminate implementation constructs, such as “software”• Replace or eliminate vague terms: “system” “computer”• Equate synonymous terms: “customer” and “client”
“client”• Eliminate operation names, if possible (such as “transaction”)• Be careful in what you really mean: can a client be a library
employee? Is it “book copy” rather than “book”?• Eliminate individual objects (as opposed to classes). “book’s
code” attribute of “book copy”
28
![Page 29: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/29.jpg)
Relationships• From the problem statement:
– employee operates station– station has bar code reader– bar code reader reads book copy– bar code reader reads identification card
• Tacit knowledge:– library owns computer– library owns stations– computer communicates with station– library employs employee– client is member of library– client has identification card
29
![Page 30: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/30.jpg)
Initial Class Diagram
30
![Page 31: Object-oriented Design CSCI 5801: Software Engineering](https://reader035.vdocuments.net/reader035/viewer/2022062321/56649e175503460f94b033e2/html5/thumbnails/31.jpg)
Initial Sequence Diagram
31