Top Banner
Object-Oriented Modeling Chapter 10 CSCI 1302
24

Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

Jan 01, 2016

Download

Documents

Gillian May
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

Object-Oriented Modeling

Chapter 10CSCI 1302

Page 2: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 2

Outline

• The Software Development Process• Discovering Relationships Among

Classes– Association– Aggregation and Composition– Inheritance

• Class Design Guidelines– Designing a Class– Using the Visibility Modifiers

Page 3: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 3

Outline

• Class Design Guidelines (cont.)– Using the static Modifier– Using Inheritance or Composition– Using Interfaces or Abstract Classes

• Framework-Based Programming Using the Java API

Page 4: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 4

Software Development Process

• Software products follow a general process

Requirement Specification

System Analysis

System Design

Testing

Implementation

Maintenance

Deployment

Page 5: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 5

Requirements Specification

• A formal process that seeks to understand the problem and document in detail what the system should do

• Close interaction between users and designers

• Real world projects are not as clearly defined or as simple as examples in class or book

Page 6: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 6

System analysis

• Analyze the business process in terms of data flow

• Identify input and output• Model the system’s behavior

Page 7: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 7

System design

• Process of designing the system’s components

• Many levels of abstraction to decompose the problem into manageable components

• Identify classes and interfaces and establish relationships among them

Page 8: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 8

Implementation

• Translate the design into programs• Separate programs are written for each

component• Involves coding, testing, and debugging

Page 9: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 9

Testing

• Ensures that the code meets the requirements specification and weeds out bugs

• Independent testers are usually used to conduct testing

Page 10: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 10

Deployment

• Makes the project available for use• Applets – Install on a web server• Application – Installing on client’s

computer• Projects consist of many classes, java

often packages all of them into a Java archive file (.jar file)

Page 11: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 11

Maintenance

• Changing and improving the product• Periodic upgrades• Bug fixing• Incorporate any changes

Page 12: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 12

Discovering Relationships

• Three types of class relationships– Association– Aggregation– Inheritance

Page 13: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 13

Association

• General binary relationship that describes an activity between two classes

Student Faculty Course * 5..60

Take Teach 0..3 1

Teacher

public class Student {

/** Data fields */ private Course[]

courseList;

/** Constructors */

/** Methods */

}

public class Course {

/** Data fields */ private Student[]

classList;

private Faculty faculty;

/** Constructors */

/** Methods */

}

public class Faculty {

/** Data fields */

private Course[]

courseList;

/** Constructors */

/** Methods */

}

Page 14: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 14

Association

• Illustrated using a solid line with optional label (“Take” and “Teach”)

• Optional triangle to indicate direction of relationship

• Each class may have a role name (“Teacher”)

• Each class may specify multiplicity• * - unlimited, m..n is an inclusive range• Usually represented as a data field

Page 15: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 15

Aggregation and Composition

• Aggregation is a special form of association that represents an ownership relationship between two classes

• Models “has-a” relationships• Object may be owned by other

aggregated objects, if exclusively owned, that is composition

• Empty diamond – aggregation, filled diamond – composition

Page 16: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 16

Aggregation and Composition

Name Address Person

Composition Aggregation

public class Name {

/** Data fields */

/** Constructors */

/** Methods */

}

public class Person {

/** Data fields */

private Name name;

private Address address;

/** Constructors */

/** Methods */

}

public class Address {

/** Data fields */

/** Constructors */

/** Methods */

}

Page 17: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 17

Inheritance

• Models “is-a” relationship between two classes

• “Strong is-a” describes direct inheritance, extending a class

• “Weak is-a” describes a class that has certain properties, implementing an interface

Person

Student Comparable

public class Student extends Person

implements Comparable {

}

Page 18: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 18

Case Studies

• Model the application in terms of cooperative objects

• Building an object-oriented system1. Identify classes for the system2. Describe the attributes and methods

in each class3. Establish relationships among classes4. Create classes

Page 19: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 19

Designing a Class

• Class should describe a single entity, and all the class operations should fit together to support a coherent purpose

• Used by many different customers, should be able to customize through properties and methods

• Designed for reuse (see p. 358)• Should provide a public no-arg

constructor, override equals and toString

Page 20: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 20

Using Visibility Modifiers

• Class can present two contracts: one for users, one for extenders

• Make fields private and accessor/mutator methods public if intended for users

• Make fields or methods protected if they are intended for extenders

• Use private to hide data from direct access by clients

Page 21: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 21

Using the static Modifier

• A shared property among all instances of a class should be declared static

• Non-instance specific methods should be declared as a static method

Page 22: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 22

Using Inheritance or Composition

• Inheritance – “is-a” relationshipApple is a Fruitpublic class Apple extends Fruit

• Composition – “has-a” relationshipPerson has a namepublic class Person { private Name name;}

Page 23: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 23

Using Interfaces or Abstract Classes

• Both used to generalize common features

• “Strong is-a” relationship that clearly describes a parent-child relationship should be modeled using classes

• “Weak is-a” or “is-kind-of” relationship indicates an object has a certain property and should be modeled using interfaces

Page 24: Object-Oriented Modeling Chapter 10 CSCI 1302. CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.

CSCI 1302 – Object-Oriented Modeling 24

Framework-Based Programming

• Classes and interfaces provided by the Java API allow developers to harness the power of the framework

• GUI API established a framework for developing GUI programs

• Using these classes and interfaces to create applications is framework-based programming