Object-Oriented Software Development Software Development Process  Analyze Relationships Among Objects  Class Development  Class Design Guidelines 

Download Report

Transcript Object-Oriented Software Development Software Development Process  Analyze Relationships Among Objects  Class Development  Class Design Guidelines 

Object-Oriented Software Development
Software Development Process
 Analyze Relationships Among Objects
 Class Development
 Class Design Guidelines

Requirement Specification
Software
Development
Process
System Analysis
System Design
Implementation
Testing
Deployment
The waterfall model
Maintenance
Software Development Process
1. Requirements Specification: Understand the problem
and document in details what it needs to do. This phase
involves close interaction between users and designers.
2. System Analysis: Analyze the business process in
terms of data flow, and to identify the system’s input
and output. Part of the analysis entails modeling the
system behavior. The model is intended to capture the
essential elements of the system and to define services
to the system.
Software Development Process
3. System Design: Design the system components. This
phase involves the use of many levels of abstraction to
decompose the problem into manageable components,
identify classes and interfaces, and establish
relationships among the classes and interfaces.
Software Development Process
4. Implementation: Translate the system design into
programs. Separate programs are written for each
component, and they are put to work together. This phase
requires the use of an OOP language like Java. The
implementation involves coding, testing and debugging.
Software Development Process
4. Implementation: Translate the system design into
programs. Separate programs are written for each
component, and they are put to work together. This phase
requires the use of an OOP language like Java. The
implementation involves coding, testing and debugging.
Software Development Process
5. Testing: Ensure that the code meets the requirements
specification and weeds out bugs. An independent team
of software engineers not involved in design and
implementation of the project usually conducts such
testing.
6. Deployment: Make the project available for use.
7. Maintenance: Change and improve the product.
Periodically upgrade the product to fix newly
discovered bugs and incorporate changes.
Relationships among Classes

OOP is centered on objects.

The first step: Identify the objects and establish
relationships among them.

The relationships can be classified into three types:
1. Association: has-a relationship
2. Aggregation
3. Inheritance: is-a relationship
Association
 Association represents a general binary relationship that
describes an activity between two classes.

A student taking a course is an association between the
Student class and the Course class.

A faculty member teaching a course is an association
between the Faculty class and the Course class.
Student
5..60
Take
* Course
0..3
Teach
1
Teacher
Faculty
Association: UML
 An association is is illustrated using a solid line between the two
classes with an optional label that describes the relationship (see
labels Take and Teach).

Each relationship may have an optional small black triangle that
indicates the direction of the relationship.

Each class involved in the relationship may have a role name
played by the class in the relationship.
Student
5..60
Take
* Course
0..3
Teach
1
Teacher
Faculty
Association: UML

Each class involved in the association may specify a
multiplicity. A multiplicity could be a number or an
interval that specifies how many objects of the class are
involved in the relationship.

The caharacter * means unlimited number of objects,
and an interval 1..u means the number of objects
should be between 1 and u.
Student
5..60
Take
* Course
0..3
Teach
1
Teacher
Faculty
Association
 Association may exist between objects of the same
class.

For example, a person may have supervisor.
Person 1
1
Supervise
Association, cont.
An association is usually represented as a data field in the
class.
public class Course {
private Faculty faculty;
/**Constructors*/
/**Methods*/
}
public class Person {
private Person supervisor;
/**Constructors*/
/**Methods*/
}
Has-a relation
 has-a,
 Has-a
part-of, or owns.
relationship holds when one object has
another object as component: object has a
(stores) reference to another object. It may use
another object to store its state or do its work.
Aggregation

Aggregation is a special form of association, which represents an
ownership relationship between two classes.

Aggregation models the relationship like has-a, part-of, owns,
and employed-by.

An object may be owned by several other aggregated objects.
An example of aggregation
Composition
Composition is a stronger form of aggregation.
 In a composite object the components exists only as part of the
composite.
 Rules of thumb:

1) The whole and parts have coincident lifetimes.
2) Both classes represent physical items.

Examples: An engine is a part a car; a package is a part of a
shipment; employee is a part of a team.
Composition
Owned by
Magazine
*
Aggregation
1
*
Publisher
Employed by
*
Expert
Consultant
Composition: UML Notation
3. Inheritance
 Inheritance models the is-a relationship between two classes.

A strong is-a relation describes a direct inheritance relationship
between two classes. Class Student inherits from the Person
class.

A week is-a relation describes that a class has certain properties.
A week is-a relationship can be represented using interfaces.
Student
Person
Faculty
2. Inheritance
public class Student extend Person
{
/**Constructors*/
/**Methods*/
}
public class Faculty extend Person
{
/**Constructors*/
/**Methods*/
}
Is-a relation

Is-a relationship holds when class is a subtype of another class It
may use another object to store its state or do its work.

All the properties: data and member functions unless overriden,
are inherited from a base class.

Constructor for subclass will call the constructor for base class
prior to any other actions.

Examples:
Class Dog is inherited from a class Animal.
Class Circle is inherited from abstract class Shape.
Major Inheritance Types
1. Inheritance for Extension
2. Inheritance for Specialization
3. Inheritance for Specification
4. Inheritance for Limitations
5. Inheritance for Construction
6. Inheritance for Combination
1. Inheritance for Extension
 The subclass adds new functionality to the base
class.

It does not change any inherited behavior
 The
first most common form of inheritance
Example: Animal  (Dog, Cat)
2. Inheritance for Specialization

The subclass is a special case of the super class.
Specialized class redefines some of the methods
of the superclass by overriden them.
 Specialization is useful a class

… with a more special behavior than superclass
… that is a variation of the superclass
…with more efficient implementation
Example: MyApplet  Applet
3. Inheritance for Specification
The second most use of inheritance
 The superclass defines behavior that is implemented in
the subclass
 All classes maintain a certain specification, which is a
common interface (classes basically implements the same
methods)
Example: Delivery Company 
(Air-Delivery Company,
Ground-Delivery Company,
Courier Company)
Method deliver

4. Inheritance for Limitation
The child class restricts the use of some of the
behavior inherited from a parent class.
Should be avoided
Example:
5. Inheritance for Construction
 A class
can often inherit almost all of its
functionality from a parent class, perhaps
changing only the names of the methods used to
interface to the class, or modifying the
arguments.
Example:
The class Stack is constructed using inheritance from
the class Vector.
pop(), push()
6. Inheritance for Combination
 It
is common to form a new abstraction by
combining features of two or more abstractions.
 A new class extends an existing class and
implements an interface.
Example: A teaching assistant may have characteristics of
both teacher and a student.
Class Development
1. Identify classes for the system.
2. Describe attributes and methods in each class.
3. Establish relationships among classes.
4. Create classes.
Example 9.1 Borrowing Mortgages
Name
1
Has
1
1 Live
Person
-name: Name
-address: Address
Defined in
Example 8.6
+Person()
+Person(name: Name, address: Address)
+getName(): Name
+setName(name: Name): void
+getAddress(): Address
+setAddress(address: Address): void
+toString(): String
Borrow
Borrower
Mortgage
-mortgage: Mortgage
- annualInterestRate;
- numOfYears;
- loanAmount;
Name
1
Address
-street: String
-city: String
-state: String
-zip: String
+Address()
+Address(street: String, city: String,
state: String, zip: String)
getStreet(): String
+getCity(): String
+getState(): String
+getZip(): String
+setStreet(street: String): void
+setCity(city: String): void
+setState(state: String): void
+setZip(zip: String): void
+getFullAddress(): String
+Borrower()
+Borrower(name: Name, address: Address)
+getMortgage(): Mortgage
+setMortgage(mortgage: Mortgage): void
+toString(): String
Mortgage
Person
Borrower Address
Example 9.1 Borrowing Mortgages
1
Has
1
Name
Person
-name: Name
-address: Address
-fistName
-mi
-lastName
+Person()
+Person(name: Name, address: Address)
+toString(): String
Borrow
Mortgage
Borrower
-mortgage: Mortgage
-annualInterestRate
-numOfYears
-loanAmount
+Borrower()
+Borrower(name: Name, address: Address)
+toString(): String
(W/o getters and setters!)
1 Live
1
Address
-street: String
-city: String
-state: String
-zip: String
+Address()
+Address(street: String, city: String,
state: String, zip: String)
+getFullAddress(): String
Example: Account
UML: Classes
UML Notation:
The abstract class name and the abstract
method names are italicized.
Object
Shape
-color: String
-filled: boolean
+getColor(): String
+setColor(String color): void
+isFilled(): boolean
+setFilled(boolean filled): void
+findArea(): double
+findPerimeter(): double
+display(): void
Circle
Cylinder
-radius: double
-length: double
+getRadius(): double
+setRadius(radius: double): void
+getLength(): double
+setLength(length: double): void
+findVolume(): double
Rectangle
-width: double
-length: double
+getWidth(): double
+setWidth(width: double): void
+getLength(): double
+setLength(length: double): void
UML: The Rational Class
1
java.lang.Number
+byteValue(): byte
+shortValue(): short
+intValue(): int
+longVlaue(): long
+floatValue(): float
+doubleValue():double
java.lang.Comparable
+int compareTo(Object)
Rational
-numerator: long
-denominator: long
+Rational()
+Rational(numerator: long, Denomination: long)
+getNumerator(): long
+getDenominator(): long
+add(secondRational: Rational): Rational
+multiply(Rational secondRational): Rational
+subtract(Rational secondRational): Rational
+divide(Rational secondRational): Rational
+toString(): String
-gcd(n: long, d: long): long
1
Add, Subtract, Multiply, Divide
UML: Package
Class Design Guidelines

Hide private data and private methods.

A property that is shared by all the instances of the
class should be declared as a class property.

Provide a public default constructor and override
the equals() method and the toString()
method defined in the Object class whenever
possible.
Class Design Guidelines, cont.

Choose informative names and follow
consistent styles.

A class should describe a single entity or a set of
similar operations.

Group common data fields and operations shared
by other classes.
Example 9.4
Designing Generic Classes

Objective: This example gives a generic class for
matrix arithmetic. This class implements matrix
addition and multiplication common for all types
of matrices.
UML: Package