Introduction To Object-Oriented Analysis and Object-Oriented Design
Introduction To Object-Oriented Analysis and Object-Oriented Design
Mitchel G. Fry
Overview
Object-oriented programming (OOP) is a way to organize
and conceptualize a program as a set of interacting objects.
1-2
Module Map
Key Object-Oriented Systems Concepts
Objects and Classes
Encapsulation
Methods and Variables
Inheritance
Message Passing and Polymorphism
Basic Software Lifecycle Concepts
Introduction to OOA/OOD
1-3
Object-Oriented Programming
Object-oriented programming (OOP) is a way to organize and
conceptualize a program as a set of interacting objects.
needed.
The programmer specifies how these various object will
1-4
What is an Object?
Real-world objects have attributes and behaviors.
behaviors
Examples:
Dog
1-5
Software Objects
Writing software often involves creating a computational model
of real-world objects and processes.
behaviors.
Your best bet is to think in terms as close as possible to the
1-7
Classes
The definitions of the attributes and methods of an object are
organized into a class.
class Thus, a class is the generic definition
for a set of similar objects (i.e. Person as a generic definition
for Jane, Mitch and Sue)
programming language.
One or more objects described by the class are instantiated
at runtime.
The objects are called instances of the class.
1-8
Classes - Cont’d
Each instance will have its own distinct set of attributes.
Every instance of the same class will have the same set of
attributes;
every object has the same attributes but,
each instance will have its own distinct values for those
attributes.
1-9
Bank Example
The "account" class describes the
attributes and behaviors of bank class: Account
accounts.
The “account” class defines two
number:
1 - 10
Bank Example - Cont’d
When the program runs there will Instance #1
be many instances of the account number: 054
class.
Each instance will have its own
balance: $19
Instance #3
number: 036
balance: $941
1 - 11
Encapsulation
When classes are defined, programmers can specify that
certain methods or state variables remain hidden inside the
class.
These variables and methods are Visible Methods
accessible from within the class, but not
Hidden
accessible outside it. State
The combination of collecting all the Variables
and
attributes of an object into a single class Methods
definition, combined with the ability to hide
some definitions and type information Visible Variables
within the class, is known as
encapsulation.
Class
Definition
1 - 12
Graphical Model of an Object
Instance balance()
variables
Methods
accountNumber()
1 - 13
Instance Methods and Instance Variables
The methods and variables described in this module so far are
know as instance methods and instance variables.
private.
It is necessary to instantiate (create an instance of) a class to
1 - 14
Class Methods and Class Variables
In addition to instance methods and instance variables, classes
can also define class methods and class variables.
1 - 15
Class Variables
A class variable defines an attribute of an entire class.
In contrast, an instance variable defines an attribute of a
Account
class
variable count: 3 num: 036
num: 054 num: 712
bal: $19 bal: $240 bal: $941
printCount()
Class
method
1 - 16
Inheritance
The advantage of making a new class a subclass is that it will
inherit attributes and methods of its parent class (also called
the superclass).
1 - 17
Subclasses
When a new class is developed a programmer can define it to
be a subclass of an existing class.
Subclasses are used to define special cases, extensions, or
class SavingsAccount
class Account { extends Account {
method acctNum() {…} method rate() {…}
method balance() {…} }
method deposit() {…}
method withdraw() {…}
} class CheckingAccount
extends Account {
method withdraw() {…}
}
1 - 19
New Account Types - Cont’d
Account SavingsAccount CheckingAccount
rate() withdraw()
1 - 20
Messages
Messages are information/requests that objects send to other
objects (or to themselves).
Message components include:
Manager Employee
Message
To: Employee
Method: getHired
Parameters: salary = $45,000, start_date = 10/21/99
1 - 21
Benefits of Messages
Message passing supports all possible interactions between
two objects.
1 - 22
Polymorphism
Polymorphism is one of the essential features of an object-
oriented language; this is the mechanism of decoupling the
behavior from the message.
1 - 23
Polymorphism – Cont’d
There are many forms of Polymorphism in object-oriented
languages, such as:
they can be applied to several types such as int, floats, strings, etc.
Overriding: This refers to the feature of subclasses that replace the
1 - 24
OO Concepts Summary
Object-oriented programming is a way of conceptualizing a
program as groups of objects that interact with one another.
A class is a general template used to create objects.
1 - 25
Module Map
Key Object-Oriented Systems Concepts
Basic Software Lifecycle Concepts
Software Lifecycles
Common Lifecyle Activities
Common Lifecyle Flows
Introduction to OOA/OOD
1 - 26
Software Lifecycles
Software lifecycles describe the evolution of a software
project from conception of the need for a software system to
the retirement or replacement of the resulting system.
1 - 27
Common Lifecycle Activities
Project Charter (definition): General description or problem
statement, top level business scenarios.
Analysis: Systems level, low detail, problem space oriented.
1 - 28
Common Lifecycle Flows
Lifecycle flows (there are just about as many of these as there
are software projects…) can generally be characterized as one
of the following types:
Sequential
Waterfall method, Structured Analysis & Design
Iterative, Spiral and Recursive Methods
There are a huge variety of these
“Agile” or “LightWeight” Software Methods fit into this class
Parallel Effort
Unmanaged, Chaotic
1 - 29
Analysis and Design Space
1 - 30
Analysis and Design Space - Cont’d
1 - 31
Module Map
Key Object-Oriented Systems Concepts
Basic Software Lifecycle Concepts
Introduction to OOA/OOD
1 - 32
Use Cases
Use cases describe the basic business logic of an application.
Use cases typically written in structured English or Diagrams
1 - 33
Use Cases Diagrams
1 - 34
Class Responsibility Collaborator Cards
A CRC model is a collection of CRC cards that represent
whole or part of an application or problem domain
The most common use for CRC models is to gather and
1 - 35
CRC Example
Class
Information
Methods and
Attributes
Collaborators
1 - 36
CRC Card Layout
Class Name:
Parent Class: Subclasses:
Responsibilities:
1 - 37
Sequence Diagrams
1 - 39
Class Diagrams
Class diagrams (object models) are the mainstay
of OO modeling
They are used to show both what the system will be able to
do (analysis) and how it will be built (design)
Class diagrams show the classes of the system and their
interrelationships
Inheritance
Aggregation
Associations
1 - 40
Class Diagram
1 - 41
UML Models
1 - 42
OOA/OOD Exercise # 1
This exercise is to learn an object-oriented analysis and design
(OOA/OOD) methodology known as responsibility driven
design.
Using the real world structure of a instant teller machine, model the
objects involved (attributes and behaviors) and their relationships (who
sends messages to whom).
Each object is represented on a 3x5 note card.
You focus on identifying the various responsibilities that are needed for
the operation of an instant teller system and who (what object) should
implement those responsibilities.
This is much like laying out an organizational flow chart. Layout the
cards on the table or tape them on a wall. Re-arrange, add new cards
and throwaway cards until it looks and feels “right” to you.
1 - 43