IntroOOADNew

Download Report

Transcript IntroOOADNew

CIS225 – Advanced Java
Introduction to ObjectOriented Analysis and
Design
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
1
Introduction
This presentation introduces objects, classes,
class inheritance and interfaces.
You will learn the concepts of objectoriented programming. Heavy emphasis is
placed on the development of software
systems using the Object-Oriented Paradigm
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
2
Introduction
The key to object-oriented programming is to
model the application in terms of cooperative
objects that reflect reality.
You design classes that describe the behavior
of these objects. Carefully designed classes
are the key to a successful application.
There are many levels of abstractions in
system design: method abstraction, class
abstraction, encapsulation, etc
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
3
Overview
The Object-Oriented Paradigm
 Managing Complexity with Abstraction
 Building a Specification Model
 Finding Objects and Identifying
Responsibilities
 Specifying Static and Dynamic Behavior
 Introduction to the Unified Modeling
Language
 Introduction to Design Patterns
 Summary

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
4
The Object-Oriented Paradigm
is defined as a “set of theories,
standards, and methods that
together represent a way of
organizing knowledge
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
5
Benefits of O-O Technology
Reduces the cost of software development:
•
Provides the software developer with realworld, programmable components
•
Provides the capability to share and reuse
code with O-O techniques that reduce time to
develop applications
•
For example: to create a button, you simply use
the JButton class to create the instance of
JButton - don’t reinvent the wheel
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
6
Benefits of O-O Technology cont.
Reduces the cost of software development:
•
Provides the capability to localize and
minimize the effects of modifications through
programming abstraction mechanisms for
faster enhancement development and provides
more reliable and robust software
•
Manages complexity allow developers to
address more difficult applications
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
7
Managing Complexity with Abstraction
History
In the early 1960’s, developers had two major
constraints :
•Performance limited in processor speed the
average desktop computer of today is faster than the
largest machines of the60s
•Using less core(memory) and storage capacityvirtual memory had not
been invented.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
8
HistoryHistory(cont.)

The programming language that we use directly
influence the way that we view (model) reality.

In the 1970s, we used the imperative programming
paradigm for modeling realityC, Pascal, and PL/1 – the structured method
high degree of coupling, and poor cohesion

In the 1980s, we used SQL and 4GL with relational
databases. We used a data-modeling paradigm
entity-relationship diagrams
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
9
History(cont.)

In the 1990s, we used C++, Smalltalk, and Objective
C -object-oriented (O-O) paradigm for modeling
realityThe object-orientation paradigm using these
languages had many limitations – high cohesion,
tight coupling

Java now provides us with a refined version of the
O-O paradigm. We have added a few new keywords
and additional features and data types.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
10
History(cont.)

Most importantly, programmers now have add a
modeling mechanism to view and model reality.

Think what it means to compute
How we organize our information inside a computer
system
How we describe our view (model) of reality


CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
11
The Object-Oriented Paradigm cont.
 Classes
and Objects
 Object-Oriented Principles
 OO Model of Computation
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
12
Classes
A
class can be viewed from four
different perspectives:
Modeling
Design
Implementation
Compilation

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
13
Classes
The class is the essential Java
construct.
A class is a template or blueprint
for objects. To program in Java, you
must understand classes and be able
to write and use them.
.A program is defined by using one
or more classes.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
14
Classes - From a modeling perspective

a class is a template for a category and
defines:
1.
2.
Characteristics (attributes) - data variables
Services (behaviors) - methods
Its interface is the protocols used to access an
object’s services and its internal state
 Its implementation are the internal
procedures for providing services
Rules and Policies – constraints that are
applied
Relationships – peer-to-peer, hierarchical,
generalization/specialization

3.
4.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
15
Classes- From a design perspective
a class is a special kind of object
 It is a collection of all the objects instantiated
from it
 It is used to create and destroy objects that
belong to its collection
 It is used to hold common data and provide
for group services such as:

Find an instance
 Keep averages
 Hold shared information

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
16
Classes -From an implementation perspective
 a class is a “global” object with class data
members and class services
 Applications can access the class services
by using the class’ name

An application can create objects by using
its constructor to “instantiate” an object

A class is used to implement the category
concept in the Java programming language
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
17
Classes -From a compiler’s perspective
 the class is a programmer’s defined data type

It is a mechanism for defining and creating
runtime objects
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
18
The 13 O-O Basic Principles
1.
Encapsulation
The object contains both the data and the code to
manipulate the data. A black box provides
encapsulation the hiding of unimportant details
2.
Information Hiding
The object that contains the data defines the
services available to other objects and hides the
data and implementation details
3.
Message Passing
 An object may communicate with another
object only by exchanging messages
- Advanced Java Richard C.
(parameters) CIS225
Lee and William M. Tepfenhart
19
The 13 O-O Basic Principles(cont.)
4. Late Binding

The specific receiver of any given message is not
known until runtime. So the determination of which
method to invoke cannot be made until run time.

The virtual machine, not the compiler, selects the
appropriate method.

Late binding enables us to model a real behavior of the
world –
Example: when a class is scheduled, it is unknown
who will attend or how many students. You only
know once the class begins. Gen/Spec with
polymorphism (#8) principle
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
20
The 13 O-O Basic Principles(cont.)
5. Delegation

Work is passed via message-passing from one object
(client) to another object (agent) until it finally reaches
the object that has both the data and code to perform the
work –

can delegate the authority to get the work done; cannot
delegate the responsibility -an example of information
hiding principle

Delegation is sometimes called the perfect bureaucratic
principle
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
21
The 13 O-O Basic Principles(cont.)
6. Class/Instance/Object
Categorizing helps us to organize the complex
world in which we live.
All objects are instances of a class and can be
created or deleted at runtime
How an object provides a service is determine
by the class of which the object is an instance
Thus, all objects of the same class, use the same
method (code)
in- response
to aC. specific service 22
CIS225
Advanced Java Richard
Lee and William M. Tepfenhart
request
The 13 O-O Principles cont.
7. Generalization/Specialization without
Polymorphism
 Classes can be organized by using a
hierarchical inheritance structure

In the structure, the specialized class (subclass)
inherits the state (data fields), the behavior (set of
methods), and the relationships from the
superclass

An abstract superclass is a class that is used
to create only subclasses: therefore there are no
direct instances of that class.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
23
Abstract Class (contd.)
Abstract classes are like regular classes with data and
methods, but you cannot create instances (objects) of
abstract classes using the new operator.
An abstract method cannot be placed in a nonabstract
class.
If a subclass of an abstract superclass does not implement
all the abstract methods, the subclass must be declared
abstract.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
24
Abstract Class (contd.)
A classes that contains abstract methods must be abstract.
However, it is possible to declare an abstract class that contains
no abstract methods.
A subclass can be abstract even if its superclass is concrete.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
25
The 13 O-O Principles cont.
8. Generalization/Specialization with
Polymorphism
 The subclass inherits the attributes,
relationships, prototype, and methods
from the superclass that is higher in the
tree.
 Subclasses can create their own method
to override behavior from the superclass
to provide the same service.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
26
The 13 O-O Principles
9. Relationships
 Associations and aggregation are used to
capture the collaboration between objects
necessary to provide a service to a client
- called a link

Types of relationships include:
association, aggregation, composition,
link, generalization, specialization
will discuss later with examples
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
27
The 13 O-O Principles cont
The instanceof operator can help us learn the class of an
object.
Student x = new UndergraduateStudent();
if(x instanceof UndergraduateStudent ){
System.out.println(“Mr. X is an
undergraduate student”);
}else{
is a
graduate student”);
System.out.println(“Mr. X
}
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
28
The 13 O-O Principles cont
10. Interface/Instance/Object
 All objects that implement an interface are
instances of that interface

Interfaces define types

Instances of an interface cannot be created
(instantiated) or destroyed (deleted) as an
instance interface.

Each must be created or destroyed as an
instance of the class to which it is a member.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
29
The 13 O-O Principles cont
11. Generalization/Specialization of
Interfaces
 Interfaces can be organized by using a
hierarchical inheritance structure

The specialized interface inherits the
service protocol from the generalized
interfaces that are higher in the (tree)
structure.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
30
The 13 O-O Principles cont
12. Reflection
 Each object knows detailed information
about the classes and interfaces of which
it is an instance

This means that an application can at
runtime acquire detail information about
the object from the object itself.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
31
The 13 O-O Principles cont
12. Reflection cont’d. ways:
1. Determine the class of the object
2. Get info about a class’s modifiers, member
variables, methods, constructors, and
superclass
3. Find out what constants and method
declarations belong to an interface
4. Create an instance of a class whose name is not
known until runtime
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
32
The 13 O-O Principles cont
12. Reflection cont’d. ways:
5. Get and set the value of an object’s field , even
if the field name is not known to your
program until run time.
6. Invoke a method on an object, even if the
method is not known until runtime.
7. Create a new array, whose size and component
type are not known until runtime, and then
modify the array’s components.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
33
The 13 O-O Principles cont
12. Reflection cont’d.
To make your programs easier to debug and
maintain do not use Method objects.
Instead use interfaces and then implement them
in the class that performs the needed action
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
34
The 13 O-O Principles cont
13. Multithreading
 Each object can have concurrent
execution paths
This means that an object can handle
multiple events (or service requests) in a
concurrent manner)
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
35
Refactoring
Martin Fowler coined this term for restructuring code in a
Disciplined way –make small transformation to your code
To:
Example (From):
SelectableShape
Car Shape
HouseShape
selected
selected
setSelected
isSelected
setSelected
selected
setSelected
isSelected
isSelected
CarShape
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
HouseShape
36
O-O Paradigm -Objects
 An
object is the most fundamental
concept/mechanism of O-O
programming
 There are three different ways of
looking at objects:
 Application modeling view
 Design modeling view
 Formal viewpoint
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
37
Objects - From an application modeling view

An object has the following components:
1.
2.
Characteristics – internal information that describes
the object (attribute name and value)
Services (behaviors)– a collection of services that has
some semantic meaning sometimes called a protocol
a. interface (prototype internal information)
b. implementation (method)
3. Unique Identifier – Each object is given a unique ID
at creation and cannot be changed. Usually the
machine id number plus the time in milliseconds -
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
38
Objects - From an application modeling view cont.

An object has the following components:
4. Rules and Policies – establish constraints
which are applied to the object
5. Relationships – how objects stand in relations
with other objects peer-to-peer or hierarchical
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
39
Objects
 From a design modeling view an object:
1. Is an example (instance) of a category
(class) form a hierarchy of gen/spec
2.
May be an example of a type (interface)
A type is a collection of service declaration
(service name, arguments, return type and
exception thrown) with no implementation
code
3. May be a “metaclass” object- may have
attributes, services, object relationships, and
rules; however may not be in a gen/spec
- Advanced Java Richard C.
relationshipCIS225
Lee and William M. Tepfenhart
40
Objects

From a design modeling view an object
cont. :
4. Is created by a category (class) object
5. Can communicate either synchronous
(method invocation) or asynchronous
(event generation) with other objects
6. Can be “persistently” associated with
another object in either a peer-to-peer or
hierarchical relationship
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
41
Objects

From a formal perspective an object is defined by:
 Its responsibilities – the value that it adds to the
system
 Its rule set –
-Attribute Assertions: Range, Enumeration,
and Type constraints
- Operation Assertions: Pre- and Post- and
invariance conditions
- Class invariance: A logical statement(s)
about the object that must be true at all
times
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
42
Objects cont.

From a formal perspective an object is defined
by:
 Its rule set(cont’d):
- inference engines –resolve multiple
inheritance conflicts
 Its classification –must be in some category
(class) even if it is a category of one object

Its type(s). An object may implement the
services of any specific type w/o being
constrained it its implementation of the services

Its relationships with other objects peer-to-peer
- Advanced Java Richard C.
or hierarchicalCIS225
43
Lee and William M. Tepfenhart
OO Model of Computation
 The
problem-solving view of OO
programming is different from the
pigeonhole model used with
imperative programming
 OO use terms like object, class, and
services instead of terms like
assignments, variables or memory
addresses
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
44
OO Model of Computation
 OO
uses a community of helpers that
work together to solve the problem
 OO programming uses a simulation
model of computation
 We define objects in the problem
domain that will help us solve the
problem
 We define how these objects interact
with one another and then set them
in motion
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
45
Managing Complexity with
Abstraction
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
46
Managing Complexity with Abstraction
 Complex
Systems
 Abstraction Mechanisms
 Service Activation Abstractions
 Process Control Abstractions
 Relationships
 Rules
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
47
Complex Systems

Much of the complexity of imperative
programming stems from the high degree of
coupling and poor cohesion makes the
systems inflexible and unmaintainable

Coupling – the dependence of one piece
of code on either another section of code
and/or some data storage
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
48
Complex Systems


Cohesion – how well a set of code and its
associated data fit together

A class should describe a single entity, and all
the class operations (methods) should fit
together to support a coherent purpose

We can use a class for students. We should not
include student and staff in the same class
because students and staff have different
CIS225 - Advanced Java Richard C.
entities.
Lee and William M. Tepfenhart
49
Complex Systems Consistency

Follow standard Java programming style
and naming conventions.

Choose informative names for classes, data
fields, and methods

A popular style is to place the data declaration
before the constructor, and place constructors
before methods. See UML Class and Object
diagram.doc in folder UML Folder
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
50
Complex Systems

Complex systems tend to have five key
attributes:
1. Complex systems take on the form of a
hierarchy
2. The choice of which system components are
considered primitive is arbitrary
3. Intracomponent links are usually stronger
than intercomponent links
4. Hierarchical systems are usually composed of
a few different kinds of subsystems combined
or arranged in various ways
5. A good complex system has usually evolved
from a good simple system
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
51
System Development is modeling


The development of a large system is a modeling
activity in which a series of increasingly detailed
models is developed
The different types of models include:
 Specification model – a black box model of the
system in terms of business value provided by
it
 Analysis model – a model that demonstrates
how the specification model will be realized
 Design model – a description of how the
analysis model will be coded
 Code model – an implementation of the design
model which upon compilation and execution
provides a solution to the business problem.
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
52
System Development

There are different software development
processes that can be used to control the
activities and level of detail while
developing complex systems
 Waterfall process model
 Iterative process model
 Divide-and-Conquer (Functional
Decomposition)
 The Object-oriented approach
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
53
System Development cont.

Waterfall process model
develops each system model
sequentially and describes the later
activities associated with testing,
delivery , and maintenance. Each
phase is completed before any work
is started on the next phase.

Iterative process model (rapid
programming) iteratively develop all of
the models cycling through the phases
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
54
System Development cont.


Divide-and-Conquer (Functional
Decomposition)
Take a big problem and break it into a number
of smaller problems

The Object-oriented approach
Breaks a complex system into component
parts in the form of objects and the
relationships among them
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
55
Abstraction Mechanisms

The history of software development is marked by
the introduction of successively more abstract
mechanisms that give developers better tools to
manage complexity. These include:
Type abstractions
 Service activation abstractions
 Processing control abstractions
 Relationships abstractions
 Behaviors
 Rules

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
56
Type Abstractions
 Object-oriented abstraction
mechanisms are a natural progression
of abstracting from functions and
simple data types to modules and
abstract data types and then to objects
 The
concept of an object is the
merging of two separate concepts: data
types and functions
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
57
Evolution of Data Abstraction
Basic Data Types
Functions
Abstract Data Types (ADT)
Modules
Objects (instances)
Class (category)
Class with Gen/Spec (inheritance)
Polymorphism (overriding, overloading)
Interface (type)
Class with Reflection (RTTI)
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
58
Abstractions Mechanisms -Basic Data Types
 Early assembly language programmers had
only very basic data types- basic integer,
floating point number, and character were
the core data type
 Early
programming language
extended the core set to include arrays
and extended precision versions of these
data types
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
59
Type Abstractions
 Basic data types
 Abstract data types
 Functions
 Modules
 Objects
 Class
 Class with generalization/specialization
 Polymorphism
 Interface
 Reflection
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
60
Service Activation Abstractions

Abstractions that identify the mechanisms
by which data processing is activated to
achieve business value
Function Call
 Event Processing (Asynchronous
communication)
 Message Passing (Synchronous
communication)
 Subscription (Asynchronous
communication)

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
61
Processing Control Abstractions

There are several traditional processing
control abstractions that have been
incorporated into object-oriented
approaches:
Single Program Execution
Multitasking
Sequential Execution
Multithreading

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
62
Relationships

Prior to the introduction of the object and
class abstractions, it was very difficult to
capture information about the relationships
between data items
 Generalization/specialization (gen/spec)
is a relationship between classes
 Associations and aggregations are
relationships between objects
 Behavior relationships permit both
classes and objects to be organized using
either gen/spec or association and
aggregationCIS225 - Advanced Java Richard C.
63
Lee and William M. Tepfenhart
Association

Describes a group of links with common
structure and semantics

Common semantics implies that the services
provided by each object in the same class are
the same, but they may be polymorphic
All links in an association must connect
objects from the same class to objects from
a second class
 Associations are bidirectional and may be
binary, ternary, or higher
 Association is a “weak” relationship

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
64
Association
Association represents a general binary
relationship that describes an activity between
two classes.
An association is usually represented as a data field
in the class.
Student
5..60
Take
* Course
0..3
Teach
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
1
Teacher
Faculty
65
Representing Association in Classes
An association is usually represented as a
data field in the class.
public class Student {
private Course[]
courseList;
/** Data fields */
/** Constructors */
/** Methods */
public class Course {
/** Data fields */
/** Constructors */
/** Methods */
}
}
public class Faculty {
private Course[]
courseList;
/** Data fields */
/** Constructors */
/** Methods */
}
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
66
Aggregation
Aggregation is a special form of association,
which represents an ownership relationship
between two classes. Aggregation models the
relationship like has-a, part-of, owns, and
employed-by.
Owned by
Magazine
*
1
*
Employed by
Publisher
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
*
Expert
Consultant
67
Aggregation
An object that represents the whole is
associated with a set of objects that
represent its components
 Aggregation is both transitive and
antisymmetric
 The components must be from the same
semantic domain (“composed of” not “made
of”)

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
68
Composition

•
•
•
•
An Object maybe owned by several other
aggregating objects
If an object is exclusively owed by an aggregating
object the relationship is called Composition
Example:
“A Student has a Name” is Composition
relationship
“A Student has an Address” is an Aggregation
relationship
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
69
Composition vs. Aggregation
Composition is a “strong” association
Aggregation is a “weak” association
Composition
Name
*
Aggregation
1
*
Person
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
*
Address
70
Behavior




Behavioral relationship mechanisms provide a
way to organize objects and classes in either peerto-peer (association) or hierarchical (gen/spec
and aggregation) structures
Behavioral analysis is the process of looking at
how each object (class) provides its services
In static behavior the operations in the method
will not be affected by external or internal events
With dynamic behaviors, the current state of an
object determines its behavior
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
71
Rules




Relationships are mechanisms for specifying data
semantics
Static and dynamic behaviors capture a system’s
procedural semantics
Rules are used to capture a systems declarative
semantics
Declarative semantics address the issues of global
control description and business rules
 Control rules
 Business rules
 Exception handling rules
 Contention rules
 Triggers
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
72
Building a Specification Model
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
73
Building a Specification Model
The OO way of modeling reality does not try
to organize all of reality
 We usually try to model only the relevant
features of a specific application domain
 One way of bounding the domain is to use
Use Cases
 Uses cases capture the functional
requirements and business-value propositions
of a proposed system along with the highlevel processes needed to achieve those
propositions

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
74
Building a Specification Model

A use case:
Specifies a sequence of actions, including
variants, that a system performs and that yields an
observable result of value to an actor
 Is a description of all the possible sequences of
interactions among the system and one or more
actors in response to some initial stimulus by one
of the actors
 Is a collection of possible sequences of
interactions between the system under discussion
and its external actors, related to a particular goal

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
75
Use Cases
Uses cases are concerned with the actors and
the sequences of interactions between them
 Some important concepts include:
 The goal - the business value to the user
 The system - the application
 An actor – external entity that interacts
with the system
 Use case – describes an interaction that
achieves a goal for an actor
 Use-case bundle – a collection of highly
correlated use cases

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
76
Use Cases
 The
Goal
 Use cases attempt to capture the value
propositions from an external view
 The goal is to capture the business
value of the system from the user’s
perspective
 The System
 Usually viewed as a “black-box”
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
77
Use Cases

The Actors
 Uses cases divide the world into two parts: the
system and the users (external entities that use it)
 Actors are a way of categorizing system users
who share a set of common interactions to
achieve a goal
 An actor represents an external entity that can
initiate actions or receive requests from the
system
 A specific user is an instance of an actor
 The set of requests/responses from/to the actors
represents the system boundaries
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
78
Use Cases

Use Case and Scenario
 A use case describes a system in terms of
sequences of interactions between various actors
and the system
 A scenario is a short narrative that outlines a
sequence of requests and responses between a
user and the system -“what happens next”
 A scenario describes how a user will use the
system to achieve a goal
 A use case is the generalized form of a family of
scenarios
 A scenario is a specific instance of a use case
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
79
Use Cases

The Use Case describes
 The pre-conditions that must exist for it to
be valid
 The post-conditions that define the state of
the system after the use case is concluded
 Detailed business logic that is performed
(technology independent)
 Business exceptions that can occur
 Business constraints that apply to the
system when reacting to a specific user
request
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
80
Use Cases
To effectively capture the functional aspects
of a system the description of the system must
be kept at a consistent level of abstraction
 To successfully develop use cases we must
know the dimension of the functional
description we are trying to capture
 These dimensions include:
 High-level and low-level
 Primary and secondary
 Essential and concrete

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
81
Use Cases
High-level functional descriptions
 Provide general and brief descriptions of
the essence of the business values provided
by the system
 Low-level functional descriptions
 Provide details showing the exact order of
activities, tasks, or alternatives

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
82
Use Cases




Primary functions
 Describe the essential functionality provided to
the user
Secondary functions
 Deal with rare and exceptional cases
Essential functions
 Describe business solutions that are independent
of implementation (hardware and software blackbox)
Concrete functions
 Describe use cases that are design dependent
(clear-box)
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
83
High-level, primary, essential use case diagram
Course Registration System
Register
Student
Drop Course
Add Course
Cancel Course
Admin
Prof
Delete Course
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
84
Finding Objects and Identifying
Responsibilities
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
85
Finding Objects and Identifying Responsibilities
 When
we analyze systems, we create
models of the application domain of
interest
 Although much simpler than reality, if
the model is rich enough it can help us
understand the business reality and
manage complexity
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
86
Finding Objects and Identifying Responsibilities
 With
OO analysis we model reality
with objects as building blocks
 We describe our world using object
categories (classes) or object types
(interfaces)
 We assign service prototypes to
interfaces
 We assign attributes and services to
categories
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
87
Finding Objects and Identifying Responsibilities
 We
define relationships between
classes (gen-spec, agg-comp, links)
 Interfaces can be organized using
generalization/specialization
 The description of service methods is
captured by pseudocode or UML
 The behavior of the system is modeled
as a sequence of messages sent
between objects that are instances of
the categories or types
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
88
Finding Objects and Identifying Responsibilities
 The
final OO model should:
 Organize the data into objects and
classes and give the data a structure
via relationships (gen/spec,
agg/comp, links)
 Organize the services into conceptual
groups via classes or interfaces
 Specify local functional behaviors
 Capture control or global behavior
 Capture constraints
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
89
Finding Objects and Identifying Responsibilities
Two views on how objects come into being:
empiricist and phenomenalist
 Empiricist

Objects exist already and are waiting to be
perceived
 Developers are blind to existing objects due to
their reliance on functional decomposition


Phenomenalist
Objects come from the world and our
consciousness via a dialectical process
 Real-world objects are a reflection of social
relations and the human thinking process

CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
90
Finding Objects and Identifying Responsibilities
 Objects
can be identified as use cases
are written
 Steps to finding objects:
 Obtain a narrative or informal
description of the problem
 Use the nouns, pronouns, and noun
phrases to identify objects, categories
and types
 Use verbs and predicate phrases to
identify services
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
91
Summary
 The
Object-Oriented Paradigm
 Managing Complexity with
Abstraction
 Specification Models
 Objects and Responsibilities
 Static and Dynamic Behavior
 The Unified Modeling Language
 Design Patterns
CIS225 - Advanced Java Richard C.
Lee and William M. Tepfenhart
92