Object Oriented Analysis and Design: An Overview Balaji Rajagopalan Credits: Material for the slides is drawn from a variety of sources including Object Oriented Analysis and Design using UML by Ali Bahrami. 1
What is Object Orientation (OO)? Traditional (structured) approaches viewed software along two orthogonal axes: Algorithms + Data Structures The OO centers on the object which combines the two orthogonal views 2
Why OO? Higher level of abstraction Seamless transition among different phases of software development Encouragement of good programming (Class carefully delineates interface -what the class can do and implementation of that interface - How the class does what it does) Promotes reusability Note that OO analysis and design does not make OO programming language a requirement for implementation 3
The result of using the OO approach is.. Object-Oriented (OO) systems development is a way to develop software by building selfcontained modules that can be more easily: Replaced Modified and Reused. 4
Member comes in Return Book? Yes Borrow Books? No Perform Research? No Read newspaper /books Go to counter and return the book Yes No Inter Libray Loan? No Yes 1 Yes 1 1.. * Yes Inter Library Loan Section, check out book Search for the book in the library Do Research on the topic Sit somewhere quiet and read newspaper, books, etc. 1 1 * Done? Yes Checking out Books? Go to counter and check out the book Bank Client ATM Machine Account Request Kind Enter Kind Request Amount Enter Amount Dispense Cash Request Take Cash Take Cash Request Continuation Terminate Print Receipt Process Transaction Transaction succeed Withdraw Checking Account Withdraw Successful Checking Account ViaNet Bank ATM Sytem method Access Class(es) BankDB +retrieveclient() +updateclient() +retrievesavingsaccount() +updatesavingsaccount() Account CheckingAccount #savings : Account +withdraw() returncode = "OK" +retrievecheckingaccount() +updatecheckingaccount() 1.. * Account #number: String #balance : float #bankclient: BankClient #transaction: Transaction 1 BankClient #firstname : String #lastname :String #cardnumber : String #pinnumber : String #account : Account +verifypassword() +deposit() +withdraw() #retrieveaccount() #updateaccount() #createtransaction() * Account- Transaction Savings- Checking Account.withdraw (anamount) Business Classes BankClient #firstname : String #lastname :String 1 1 withdraw using SavingsAccount method #cardnumber : String #pinnumber : String #account : Account #bankdb: BankDB +verifypassword() Has CheckingAccount #savings : Account +withdraw() -retrieveaccount() -updateaccountt() 1 1.. * Account #number: String #balance : float SavingsAccount #checking : Account BanK #bankclient: BankClient #transaction: Transaction #bankdb: BankDB +deposit() +withdraw() #createtransaction() #retrieveaccount() #updateaccountt() 1 ATMMachine #address : String #state : String Transaction #transid : String #transdate : Date #transtime : Time #transtype : String #amount :float #postbalance : float #account : Account SavingsAccount.withdraw SavingsAccount.balance - (anamount - CheckAccount.balance)) 1 Savings- Checking * Account- Transaction 1 returncode ="Insufficient funds" ATMMachine #address : String #state : String Transaction #transid : String #transdate : Date #transtime : Time #transtype : String #amount :float #postbalance : float SavingsAccount #account : Account #checking : Account -retrieveaccount() -updateaccountt() Is easy to operate: How do you rate the ViaNet Bank ATM Kiosk Interface? Very easy to use 10 9 8 7 6 5 4 3 2 1 Buttons are right size and easily can be located: 10 9 8 7 6 5 4 3 2 1 Is efficient to use: Is Fun to use: Is visually pleasing: Very appropriate Very efficient Very Very pleasing 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1 Provides easy recovery from errors: 10 9 8 7 6 5 4 3 2 1 Very easy recovery Comments: I have more to say, I would like to see you. Very Hard to use Not appropriate Very inefficient Not Fun at all Not pleasing Not at all Analysis Design Prototyping and Testing 1. Identify the users/actors (Chapter 6): Who is (or will be) using the system? 2. Develop a simple business process model The advantage of developing a business process model is that it familiarizes you with the system and therefore the user requirements 3. Develop the use case (Chapter 6): What are (or will be) the users are doing with the system? Use cases provide comprehensive documentation of the system under study Use cases capture the goal of the users and the responsibility of the system to its users Business process modeling using activity diagram Use case diagrams 4. Interaction diagrams (Chapter 7) 4.1 Develop sequence diagrams 4.2 Develop collaboration diagrams. 4.3 Iterate and refine collaboration diagram 5. Classification (Chapter 8) 5.1 Identify Classes 5.2 Identify Relationships 5.3 Identify Attributes 5.4 Identify Methods 5.5 Iterate and refine. Class diagram The process of creating sequence or collaboration diagrams is a systematic way to think about how a use case can take place, and by doing so, it forces you to think about objects involves in your application Sequence diagram 6. Apply design axioms to design classes, their attributes, methods, associations, structures, and protocols (Chapter 9) 6.1. Refine and complete the static UML class diagram (object model) by adding details to the UML class diagram (Chapter 10) 6.1.1 Refine attributes 6.1.2 Design methods and protocols by utilizing UML activity diagram for representation of method s algorithm 6.1.3 Refine (if required) associations between classes 6.1.4 Refine (if required) class hierarchy and design with inheritance 6.2 Iterate and refine (reapply Design axioms). 7.0 Design the access ayer (Chapter 11) 7.1. Create maccess layer classes by mirroring the business classes 7.2. Define relationships 7.3. Simplify classes and structures 7.3.1 Eliminate redundant classes 7.3.2 Eliminate method classes 7.4 Iterate and refine Refine UML Class diagram Withdraw using Account class insufficient funds sufficient funds CheckingAccount::+withdraw (anamount:float):returncode:string sufficient funds account Doesn't have savings acount has savings account insufficient funds Design methods by utilizing UML Activity Diagram UML Class diagram with added access and view classes 8. Designing view layer classes (Chapter 12) 8.1 Macro-level UI design Process- Identifying View layer Objects 8.2 Micro-level UI design activities: 8.2.1 Designing the view layer objects by applying design axioms and corollaries 8.2.2 Prototyping the view layer interface. 8.3. Usability and user satisfaction testing (Chapter 14): 8.4 Iterate and refine 9. Iterate and refine the design/analysis: If needed repeat the preceding steps Enter title here Create User Interface controls Cancel OK Create the forms and controls Enter title here Associate actions to the User Interface controls and their events Cancel OK Add Actions Enter title here Test/Debug Cancel OK Test the UI Done Prototype user interface 5 Usability and user satisfaction testing
Object Basics Define Objects and classes Describe objects methods, attributes and how objects respond to messages, Define Polymorphism, Inheritance, data abstraction, encapsulation, and protocol, Describe objects relationships, Describe object persistence, Understand meta-classes. 6
What is an object? The term object was first formally utilized in the Simula language to simulate some aspect of reality. An object is an entity. It knows things (has attributes) It does things (provides services or has methods) 7
Attributes (Contd.) I am a Car. I know my color, manufacturer, cost, owner and model. 8
Attributes (Contd.) I am a Fish. I know my date of arrival and expiration. 9
It does things (methods) I know how to compute my payroll. 10
Methods (Contd.) I know how to stop. 11
What is an object? (Contd.) Attributes or properties describe object s state (data) and methods define its behavior. Object is whatever an application wants to talk about. For example, Parts and assemblies might be objects of bill of material application. Stocks and bonds might be objects of financial investment applications. 12
Objects In an object-oriented system, everything is an object: numbers, arrays, records, fields, files, forms, an invoice, etc. An Object is anything, real or abstract, about which we store data and those methods that manipulate the data. Conceptually, each object is responsible for itself. l A chart object is responsible for things like maintaining its data and labels, and even for drawing itself. l A window object is responsible for things like opening, sizing, and closing itself. 13
Two Basic Questions When developing an O-O application, two basic questions always arise. What objects does the application need? What functionality should those objects have? 14
Object s Attributes and Methods Attributes represented by data type. They describe objects states. In the Car example the car s attributes are: Methods color, manufacturer, cost, owner, model, etc. define objects behavior and specify the way in which an Object s data are manipulated. In the Car example the car s methods are: drive it, lock it, tow it, carry passenger in it. 15
Objects are Grouped in Classes The role of a class is to define the attributes and methods (the state and behavior) of its instances. The class car, for example, defines the property color. Each individual car (object) will have a value for this property, such as "maroon," "yellow" or "white." 16
Employee Class John object Jane object Mark object 17
A Class is an Object Template, or an Object Factory. Boeing Airplane Objects (Boeing instances) 18
Class Hierarchy An object-oriented system organizes classes into subclass-super hierarchy. At the top of the hierarchy are the most general classes and at the bottom are the most specific 19
Class Hierarchy (Contd.) A subclass inherits all of the properties and methods (procedures) defined in its superclass. Motor Vehicle Bus Truck Car 20
Inheritance (programming by extension ) Inheritance is a relationship between classes where one class is the parent class of another (derived) class. Inheritance allows classes to share and reuse behaviors and attributes. The real advantage of inheritance is that we can build upon what we already have and, Reuse what we already have. 21
Inheritance (Contd.) Vehicle Car I know how to stop stop method is reusable Ford Mustang Taurus Thunderbird I don t know how to stop stop (mymustang) 22
Multiple Inheritance OO systems permit a class to inherit from more than one superclass. This kind of inheritance is referred to as multiple inheritance. 23
Multiple Inheritance (Contd.) For example utility vehicle inherits from Car and Truck classes. MotorVehicle Truck Car Bus UtilityVehicle 24
Encapsulation and Information Hiding Information hiding is a principle of hiding internal data and procedures of an object. Permissible operations Data Private Protocol Public Protocol Messages 25
Encapsulation and Information Hiding (Contd.) By providing an interface to each object in such a way as to reveal as little as possible about its inner workings. Encapsulation protects the data from corruption. 26
Protocol Protocol is an interface to the object. TV contains many complex components, but you do not need to know about them to use it. 27
Message Objects perform operations in response to messages. For example, you may communicate with your computer by sending it a message from hand-held controller. 28
A Case Study - A Payroll Program Consider a payroll program that processes employee records at a small manufacturing firm. This company has three types of employees: 1. Managers: Receive a regular salary. 2. Office Workers: Receive an hourly wage and are eligible for overtime after 40 hours. 3. Production Workers: Are paid according to a piece rate. 29
Structured Approach FOR EVERY EMPLOYEE DO BEGIN IF employee = manager THEN CALL computemanagersalary IF employee = office worker THEN CALL computeofficeworkersalary IF employee = production worker THEN CALL computeproductionworkersalary END 30
What if we add two new types of employees? Temporary office workers ineligible for overtime, Junior production workers who receive an hourly wage plus a lower piece rate. 31
FOR EVERY EMPLOYEE DO BEGIN IF employee = manager THEN CALL computemanagersalary IF employee = office worker THEN CALL computeofficeworker_salary IF employee = production worker THEN CALL computeproductionworker_salary IF employee = temporary office worker THEN CALL computetemporaryofficeworkersalary IF employee = junior production worker THEN CALL computejuniorproductionworkersalary END 32
An Object-Oriented Approach What objects does the application need? The goal of OO analysis is to identify objects and classes that support the problem domain and system's requirements. Some general candidate classes are: Persons Places Things 33
What are some of the application s classes? Employee Manager Office Workers Production Workers 34
Class Hierarchy Identify class hierarchy Identify commonality among the classes Draw the general-specific class hierarchy. 35
Class Hierarchy (Contd.) Employee name address salary SS# OfficeWorker Manager ProductionWorker dataentry ComputePayroll printreport dataentry ComputePayroll printreport dataentry ComputePayroll printreport 36
OO Approach FOR EVERY EMPLOYEE DO BEGIN employee computepayroll END 37
If new types of employees were added Employee name address salary SS# OfficeWorker M anager ProductionW orker dataentry ComputePayroll printr eport dataentry ComputePayroll printreport dataentry ComputePayroll printreport TemporaryOfficeW orker JuniorProductionW orker ComputePayroll ComputePayroll 38
Polymorphism Polymorphism means that the same operation may behave differently on different classes. Example:computePayroll 39
Associations The concept of association represents relationships between objects and classes. For example a pilot can fly planes. 40
Associations (Contd.) Pilot can fly flown by Planes 41
Clients and Servers A special form of association is a clientserver relationship. This relationship can be viewed as one-way interaction: one object (client) requests the service of another object (server). 42
Clients and Servers (Contd.) PrintServer Request for printing Item 43
Objects and Persistence Objects have a lifetime. An object can persist beyond application session boundaries, during which the object is stored in a file or a database, in some file or database form. 44
Summary Rather than treat data and procedures separately, object-oriented programming packages them into "objects." O-O system provides you with the set of objects that closely reflects the underlying application Advantages of object-oriented programming are: The ability to reuse code, develop more maintainable systems in a shorter amount of time. more resilient to change, and more reliable, since they are built from completely tested and debugged classes. 45