Professional Documents
Culture Documents
Object-Oriented Analysis and Design: S.Balaji
Object-Oriented Analysis and Design: S.Balaji
S.Balaji
4/15/2012
Introduction
OOAD: object-oriented analysis and design Class and object concepts Discovering classes CRC card Word problem to classes Classes and relationships Inheritance and polymorphism OOP: Object-oriented programming in Java At the end of this class you should be able to analyze a problem, design a OO solution and implement it in Java programming language
4/15/2012 2
Object-Oriented Principles
OOP
Encapsulation (class concept) -- Information Hiding -- Interface and Implementations -- Standardization -- Access Control mechanisms (private /public etc.)
Inheritance
Polymorphism
4/15/2012
What is an Object?
Object-oriented programming supports the view that programs are composed of objects that interact with one another. How would you describe an object? Using its characteristics (has a ----?) and its behaviors (can do ---?) Object must have unique identity (name) : Basketball, Blue ball Consider a ball: Color and diameter are characteristics (Data Declarations) throw, bounce, roll are behaviors (Methods)
4/15/2012
Example
objects
Object References
redRose
class
4/15/2012 6
Inheritance Hierarchy
Foo d eat( )
Food Hierarchy
IceCream eat( )
Pi zza eat( )
4/15/2012
Polymorphism (subtype)
Consider a class Food. What can you do with Food? What does it have? Consider specific food items Ice Cream, Spaghetti and Pizza. How will you eat these? (Invoke eat() operation on objects of these classes)? eat() operation is polymorphically invoked depending on the type of the item it is invoked on.
4/15/2012 8
Use-case Analysis
Use case analysis involves reading and analyzing the specifications, as well as discussing the system with potential users of the system. Actors of the LMS are identified as the librarians and borrowers. Librarians directly interact with the system whereas borrowers interact with the system through the librarian.
4/15/2012 9
addTitle
removeUpdateTitle
addItem
removeUpdateItem
addBorrower
4/15/2012
removeUpdateBorrower
10
Classes
OO paradigm supports the view that a system is made up of objects interacting by message passing. Classes represent collection of objects of the same type. An object is an instance of a class. A class is defined by its properties and its behaviors. A class diagram describes the static view of a system in terms of classes and relationships among the classes.
4/15/2012 11
Example (Take 2)
objects
Object References
redRose
class
4/15/2012 12
4/15/2012
13
Access Control
Public, protected, private Public properties and behaviors are available to any other object to use/invoke Private: available only within the objects. Protected: available within the objects and to the class hierarchy inherited from the class. (We will discuss more about this when dealing with OO concept Inheritance.)
4/15/2012 15
Relationships
Typically an application consists of many related classes. Commonly used relationships include: associations, aggregations, and generalizations.
4/15/2012
16
Association
An association is a connection between classes, a semantic connection between objects of classes involved in the association. Association typically represents has a or uses relationships. Indicated by a line,
sometimes with arrow indicating unidirectional relationship, adorned by the name of the relation, and the ends of the line adorned by cardinality of relationship and optionally by the roles connected to each class.
17
4/15/2012
Association : Examples
Person Uses Computer
Person
Owns
0..*
Car
4/15/2012
18
Roles in Association
Person
driver
drives
company car
Car
wife
Person
husband
married to
4/15/2012 19
Aggregation
Aggregation represents a relation contains, is a part of, whole-part relation. Indicated by a line adorned on the whole by a hollow diamond
4/15/2012
20
Aggregation: Example
League contains Team
*
wheel
made of
Auto
1
engine
Strong aggregation.
part
21
4/15/2012
Generalization
Generalization is a relationship between a general and a specific class. The specific class called the subclass inherits from the general class, called the superclass. Public and protected properties (attributes) and behaviors (operations) are inherited. Design representation inheritance OO concept.
4/15/2012 22
Generalization: Symbol
It represents is a relationship among classes and objects. Represented by a line with an hollow arrow head pointing to the superclass at the superclass end.
4/15/2012
23
Generalization: Example
Vehicle
Car
Boat
Truck
4/15/2012
24
Combined Example
Person
drives
0..*
Vehicle
Car
Boat
Truck
4/15/2012
25
BookTitle
MagazineTitle
Borrow er
4/15/2012
26
Dynamic Analysis
Borrow Item use case using Sequence Diagram Add Title use case using Collaboration diagram Add Item using Activity diagram Reservation state diagram
4/15/2012
27
3: findItem ( ) 4: searchItem ( )
4/15/2012
28
2: setItem ( )
itemObj 5: storeItem ( )
DB : DB
4/15/2012
29
setItem
addToTitle
updateDatabase
4/15/2012
30
Component Diagram
Business Package + Item + Loan + Title + Borrower inf ormation + Book Title + Reserv ation + Magazine Title
GUI Package + Lend Window + Return Window + Reserv ation Window + Maintenance Window
4/15/2012
31
Elements of a Class
class data declarations (variables, constants) methods
header
header
body
parameters
variables, constants
statements
selection
repetition
others
assignment
4/15/2012 32
Class Structure
class
variables constants
methods
4/15/2012
33
Defining Methods
A method is group of (related) statements that carry out a specified function. A method is associated with a particular class and it specifies a behavior or functionality of the class. A method definition specifies the code to be executed when the method is invoked/activated/called.
4/15/2012 34
3 4
Area method
4/15/2012
35
Visibility Modifiers
type Method/variable name
public
protected
nothing DEFAULT
private static
4/15/2012
..Modifiers (contd.)
private : available only within class nothing specified : DEFAULT: within class and within package protected : within inherited hierarchy (only to sub classes) public : available to any class.
4/15/2012
37
Inheritance
Inheritance is the act of deriving a new class from an existing one. A primary purpose of inheritance is to reuse existing software. Original class used to derive a new class is called super class and the derived class is called sub class. Inheritance represents is a relationship between the superclass and the subclass.
4/15/2012 38
Modifers
Visibility modifiers: private, public, protected Protected modifier is used when the entity needs to be available to the subclass but not to the public.
4/15/2012
39
Next Steps
Develop a multi-class java application Develop a application with graphical user interface Develop the solution for LMS Where can you get more info?
http://www.netbeans.org/kb/trails/java-se.html
4/15/2012
40