3-8-05
3-8-05
3-8-05
(Cont’d)
1
(Some slides omitted or modified.)
Method Signature
The signature of a method consists of the
method’s name, together with the number
and type(s) of its parameters in their given
order
3
Method Overloading Examples
These methods are overloaded:
public void someMethod (int a, int b) {….}
public void someMethod (int y) {..}
5
Constructor Overloading Examples
Multiple constructors are often defined for
an object-creating class.
Overloaded Constructor with one
parameter:
public Student (String inputName ) {..}
Overloaded Constructor with two
parameters:
public Student (String inputName, int inputID )
{..}
6
Object State
The object’s state is the current set of values that it
contains
An object is instantiated with an initial state. If any
of its methods can subsequently change its state,
the object is said to be mutable
If there are no methods that can change an
object’s state, it is said to be immutable (Ex.:
String object)
Methods that change an object’s state are called
mutators or transformers
7
Chapter 6
Object-Oriented Software Design and
Implementation
8
Software Design Strategies
FUNCTIONAL OBJECT-ORIENTED
DECOMPOSITION DESIGN
9
Object-Oriented Design (OOD)
•Focus is on the entities (objects) in a problem
11
Object-Oriented Design Process
Three steps in the process
Identify an initial set of object classes
that seem relevant to the problem
– nouns often represent objects
– verbs often represent actions
Filter the list, eliminating duplicates
Identify the responsibilities for the
reduced list of objects
12
Identify Possible Classes
Brainstorming (by a team)
Identify objects
Propose classes
Write on a blackboard
Keep going around until no one can
think of any more objects
No ideas are rejected
13
Filter List of Possible Classes
Eliminate duplicates
Decide if the classes really do represent
objects in the problem
Look for classes that are related
Over looked classes may emerge
For each class that survives the filtering
stage, create a CRC card
14
Blank CRC Card
Class Name: Superclass: Subclasses:
Responsibilities Collaborations
15
Definitions
Responsibilities An action that an
implementation of an object must be
capable of performing
Collaboration An interaction between
objects in which one object requests that
another object carry out one of its
responsibilities
16
Determine Responsibilities
Initial responsibilities
Know and return the states of the object
Called Knowledge Responsibilities
Action responsibilities Use scenario
walk-throughs, a role playing technique,
to explore the actions of a class
to explore the interactions of classes
17
Inheritance
Inheritance A mechanism by which one
class acquires (inherits) the properties
(both data fields and methods) of another
class.
Enables us to define a new class by adapting
the definition of an existing class
Superclass The class being inherited from
Derived class The class that inherits
The derived class is specialized by adding
properties specific to it 18
Address object inheritance hierarchy
Object
Address
HomeAddress CompanyAddress
WorkAddress BoxAddress
19
Package Syntax
Compilation Unit
package Identifier ;
ImportDeclaration . . .
ClassDeclaration . . .
20
Package Do’s and Don’t’s
A compilation unit can have only one
public class
Many compilation units can be in a
package
“No modifier” specifies package access
Any field or method with package access
can be accessed by any member of the
package
21
Package Example
package addressBook
Members:
class Address
class Entry
Imported by
class AddressDr
All of the variables have package
access
22