Object-Oriented Software Development F Software Development Process F Analyze Relationships Among...

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

Transcript of Object-Oriented Software Development F Software Development Process F Analyze Relationships Among...

Page 1: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Object-Oriented Software Development

Software Development Process Analyze Relationships Among Objects Class Development Class Design Guidelines

Page 2: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Software Development

Process

Requirement Specification

System Analysis

System Design

Implementation

Testing

Deployment

Maintenance

The waterfall model

Page 3: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Software Development Process

1. Requirements SpecificationRequirements Specification: Understand the problem and

document in details what it needs to do. This phase involves

close interaction between users and designers.

2. System AnalysisSystem 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.

Page 4: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Software Development Process

3. System DesignSystem 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.

Page 5: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Software Development Process

4. ImplementationImplementation: 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.

Page 6: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Software Development Process

4. ImplementationImplementation: 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.

Page 7: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Software Development Process 5. TestingTesting: 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. DeploymentDeployment: Make the project available for use.

7. MaintenanceMaintenance: Change and improve the product.

Periodically upgrade the product to fix newly

discovered bugs and incorporate changes.

Page 8: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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

Page 9: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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 FacultyCourse*5..60

Take Teach0..3 1

Teacher

Page 10: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Association: UML

Student FacultyCourse*5..60Take Teach

0..3 1Teacher

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.

Page 11: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Association: UML

Student FacultyCourse*5..60Take Teach

0..3 1Teacher

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.

Page 12: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Association Association may exist between objects of the same

class.

For example, a person may have supervisor.

Person

Supervise

1

1

Page 13: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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*/

}

Page 14: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Has-a relation has-ahas-a, part-of, or owns.

Has-a 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.

Page 15: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Aggregation Aggregation is a special form of association, which represents an

ownership relationship between two classes.

Aggregation models the relationship like has-ahas-a, part-of, owns,

and employed-by.

An object may be owned by several other aggregated objects.

An example of aggregation

Page 16: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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.

Magazine ConsultantPublisher1*

Owned by Employed by**

Expert

Composition Aggregation

Page 17: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Composition: UML Notation

Page 18: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

3. Inheritance Inheritance models the is-ais-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.

Person

Faculty

Student

Page 19: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

2. Inheritancepublic class Student extend Person

{

/**Constructors*/

  /**Methods*/

}

public class Faculty extend Person

{

/**Constructors*/

/**Methods*/

}

Page 20: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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.

Page 21: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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

Page 22: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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)

Page 23: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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

Page 24: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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

Page 25: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

4. Inheritance for LimitationThe child class restricts the use of some of the

behavior inherited from a parent class.

Should be avoided

Example:

Page 26: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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

Page 27: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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.

Page 28: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Class Development

1. Identify classes for the system.

2. Describe attributes and methods in each class.

3. Establish relationships among classes.

4. Create classes.

Page 29: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Example 9.1 Borrowing Mortgages

NameName BorrowerBorrowerPersonPersonMortgageMortgage

Name11 Has Live1 1

BorrowBorrower

-mortgage: Mortgage

+Borrower()+Borrower(name: Name, address: Address)+getMortgage(): Mortgage+setMortgage(mortgage: Mortgage): void+toString(): String

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

Defined inExample 8.6

Person

-name: Name-address: Address

+Person()+Person(name: Name, address: Address)+getName(): Name+setName(name: Name): void+getAddress(): Address+setAddress(address: Address): void+toString(): String

Mortgage

- annualInterestRate;- numOfYears; - loanAmount;

AddressAddress

Page 30: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Example 9.1 Borrowing Mortgages11 Has Live1 1

BorrowBorrower

-mortgage: Mortgage

+Borrower()+Borrower(name: Name, address: Address)+toString(): String

Address

-street: String-city: String-state: String-zip: String

+Address()+Address(street: String, city: String, state: String, zip: String)+getFullAddress(): String

Person

-name: Name-address: Address

+Person()+Person(name: Name, address: Address)+toString(): String

Mortgage

-annualInterestRate -numOfYears -loanAmount

Name

-fistName -mi -lastName

(W/o getters and setters!)

Page 31: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Example: Account

Page 32: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

UML: Classes

Circle

-radius: double

+getRadius(): double+setRadius(radius: double): void

Cylinder

-length: double

+getLength(): double+setLength(length: double): void+findVolume(): double

Shape

-color: String-filled: boolean

+getColor(): String+setColor(String color): void+isFilled(): boolean+setFilled(boolean filled): void+findArea(): double+findPerimeter(): double+display(): void

Object

Rectangle

-width: double-length: double

+getWidth(): double+setWidth(width: double): void+getLength(): double+setLength(length: double): void

UML Notation:The abstract class name and the abstractmethod names are italicized.

Page 33: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

UML: The Rational Class 1

1 Add, Subtract, Multiply, Divide

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

java.lang.Number +byteValue(): byte +shortValue(): short +intValue(): int +longVlaue(): long +floatValue(): float +doubleValue():double

java.lang.Comparable +int compareTo(Object)

Page 34: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

UML: Package

Page 35: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

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.

Page 36: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Class Design Guidelines, cont.

Choose informative names and followconsistent styles.

A class should describe a single entity or a set of similar operations.

Group common data fields and operations shared

by other classes.

Page 37: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

Example 9.4Designing 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.

Page 38: Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.

UML: Package