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

Post on 01-Jan-2016

218 views 0 download

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

Object-Oriented Software Development

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

Software Development

Process

Requirement Specification

System Analysis

System Design

Implementation

Testing

Deployment

Maintenance

The waterfall model

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.

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.

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.

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.

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.

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

Take Teach0..3 1

Teacher

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.

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.

Association Association may exist between objects of the same

class.

For example, a person may have supervisor.

Person

Supervise

1

1

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

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

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

Composition: UML Notation

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

2. Inheritancepublic 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 LimitationThe 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

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

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

Example: Account

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.

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)

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

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.

UML: Package