Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-oriented Design CSCI 5801: Software Engineering.

Similar presentations


Presentation on theme: "Object-oriented Design CSCI 5801: Software Engineering."— Presentation transcript:

1 Object-oriented Design CSCI 5801: Software Engineering

2 Object-oriened Design

3 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

4 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

5 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)

6 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 to manipulate state of object Current state of object Object Only has to understand how to call methods, not how they work Do not have to understand internal representation of object state

7 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

8 UML for Classes Example: Roster class (in Registration package)

9 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

10 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 ∞

11 Association Relationship Objects communicate via some defined relationship (other than composition) Can show complex data types passed for communication

12 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

13 Interface Relationship Class calls methods specified in interface another class implements

14 UML Example

15 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

16 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

17 Sample Sequence Diagram

18 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 database Actors 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

19 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

20 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.

21 Database Descriptor Example (ATM) Account Database Structure Field NameField TypeDescription AccountNumber Text (15 characters)Primary key, shared with other tables HasSavings Yes/NoDoes this customer have a savings account? SavingsBalance Number (must be positive) Amount in savings account HasChecking Yes/NoDoes this customer have a checking account? CheckingBalance Number (must be positive) Amount in checking account HasCredit Yes/NoDoes 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

22 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

23 API Example A 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 scenarios Constructor public Roster (int maxSize) Methods public void AddStudent(Student s) public void deleteStudent(String id) public Student[] getRoster() public booolean isOpen() public String serialize() public void deserialize(String s)

24 API Example public 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.

25 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?

26 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, ©200826

27 Candidate objects software library system station customer transaction 27 book library employee identification card client bar code reader book’s code

28 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

29 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

30 Initial Class Diagram 30

31 Initial Sequence Diagram 31


Download ppt "Object-oriented Design CSCI 5801: Software Engineering."

Similar presentations


Ads by Google