首页 > 其他分享 >Part 1: Introduction to OOAD

Part 1: Introduction to OOAD

时间:2023-03-27 11:32:13浏览次数:43  
标签:What Object objects Introduction object Part OOAD model class


Part 1: Introduction to OOAD
2
Objectives
What we will learn:
 Introduce OO concepts.
 Compare and contrast analysis and design.
 Define object-oriented analysis and design
(OOA/D).
 Illustrate a brief example.
3
What Is Object Technology?
 A set of principles
(abstraction,
encapsulation,
polymorphism) guiding
software construction,
together with
languages, databases,
and other tools that
support those
principles. (Object
Technology - A
Manager’s Guide,
Taylor, 1997.)
4
The Strengths of Object Technology
 Reflects a single paradigm
 Facilitates architectural and code reuse
 Reflects real world models more closely
 Encourages stability
 Is adaptive to change
5
 Major object technology milestones
Simula
1967
C ++
Late 1980s
Smalltalk
1972
Java
1991
The UML
1996
UML 2
2004
The History of Object Technology
6
Where Is Object Technology Used?
 Client/Server Systems
and Web Development
 Object technology
allows companies to
encapsulate business
information in objects
and helps to distribute
processing across the
Internet or a network.
7
Where Is Object Technology Used? (continued)
 Real-time systems
 Object technology
enables real-time
systems to be
developed with higher
quality and flexibility.
4
8
Differences Between OO and Structured Design
 Object-orientation (OO)
 Melds the data and data flow process together
early in the lifecycle
 Has a high level of encapsulation
 Promotes reuse of code differently
 Permits more software extensibility
9
10
Concepts of Object Orientation
11
Objectives
 Describe abstraction, encapsulation,
modularity, and hierarchy.
 Describe the physical structure of a class.
 Describe the relationship between a class
and an object.
 Define polymorphism and generalization.
12
Where Are We?
 What is an object?
 Four principles of OO
 What is a class?
 Polymorphism and
generalization
 Organizing model elements
13
 Informally, an object represents an entity,
either physical, conceptual, or software.
 Physical entity
 Conceptual entity
 Software entity
Truck
Chemical Process
Linked List
What Is an Object?
14
A More Formal Definition
 An object is an entity
with a well-defined
boundary and identity
that encapsulates state
and behavior.
 State is represented by
attributes and
relationships.
 Behavior is represented
by operations, methods,
and state machines. Object
Operations
Attributes
15
An Object Has Identity
 Each object has a unique identity, even if the
state is identical to that of another object.
Professor “M Zheng”
teaches Java
Professor “M Zheng”
teaches Java
16
Where Are We?
 What is an object?
 Four principles of OO
 What is a class?
 Polymorphism and
generalization
 Organizing model elements
17
Basic Principles of Object Orientation
Abstraction
Hierarchy
Object Orientation
Encapsulation
Modularity
18
What Is Abstraction?
 The essential characteristics
of an entity that distinguishes
it from all other kinds of
entities.
 Defines a boundary relative to
the perspective of the viewer.
 Is not a concrete
manifestation, denotes the
ideal essence of something.
19
Example: Abstraction
Student Professor
Course Offering (9:00 a.m.,
Monday-Wednesday-Friday)
Course (e.g. Algebra)
20
What Is Encapsulation?
Improves Resiliency
 Hides implementation from clients.
 Clients depend on interface.
21
Encapsulation Illustrated
 Professor Clark
needs to be able
to teach four
classes in the
next semester.
SubmitFinalGrades()
AcceptCourseOffering()
TakeSabbatical()
Professor Clark
SetMaxLoad()
Name: Michael Zheng
Employee ID: 567138
HireDate: 07/25/1991
Status: Tenured
Discipline: Finance
MaxLoad:4 SetMaxLoad(4)
22
What Is Modularity?
 Breaks up something complex
into manageable pieces.
 Helps people understand
complex systems.
23
Example: Modularity
 For example, break
complex systems into
smaller modules. Billing
System
Course Registration
System
Course
Catalog
System
Student
Management
System
24
What Is Hierarchy?
Decreasing
abstraction
Increasing
abstraction
Asset
RealEstate
Savings
BankAccount
Checking Stock
Security
Bond
Elements at the same level of the hierarchy
should be at the same level of abstraction.
25
Where Are We?
 What is an object?
 Four principles of OO
 What is a class?
 Polymorphism and
generalization
 Organizing model elements
26
What Is a Class?
 A class is a description of a set of objects
that share the same attributes, operations,
relationships, and semantics.
 An object is an instance of a class.
 A class is an abstraction in that it
 Emphasizes relevant characteristics.
 Suppresses other characteristics.
27
A Sample Class
Class
Course
Properties
Name
Location
Days offered
Credit hours
Start time
End time
Behavior
Add a student
Delete a student
Get course roster
Determine if it is full
28
Representing Classes in the UML
 A class is represented using a rectangle
with three compartments:
 The class name
 The structure (attributes)
 The behavior (operations)
Professor
- name
- employeeID : UniqueId
- hireDate
- status
- discipline
- maxLoad
+ submitFinalGrade()
+ acceptCourseOffering()
+ setMaxLoad()
+ takeSabbatical()
+ teachClass()
29
What Is an Attribute?
 An attribute is a named property of a class
that describes the range of values that
instances of the property may hold.
 A class may have any number of attributes or no
attributes at all.
Attributes
Student
- name
- address
- studentID
- dateOfBirth
30
Attributes in Classes and Objects
Class
Objects
Student
- name
- address
- studentID
- dateOfBirth
:Student
- name = “Lei Wang”
- address = “123 Main St.”
- studentID = 9
- dateOfBirth = “03/10/1987”
:Student
- name = “Ning Li”
- address = “456 People St.”
- studentID = 2
- dateOfBirth = “12/11/1989”
31
Object-Oriented Basics: Class
 E.g. A chair is a member of (instance of) a set of similar
objects (class) that we call furniture.
class: Furniture
cost
dimensions
weight
location
color
buy
sell
weigh
move
object:
theChair
cost
dimensions
weight
location
color
buy
sell
weigh
move
32
What Is an Operation?
 A service that can be requested from an
object to effect behavior. An operation has
a signature, which may restrict the actual
parameters that are possible.
 A class may have any number of operations
or none at all.
Operations
Student
+ get tuition()
+ add schedule()
+ get schedule()
+ delete schedule()
+ has prerequisites()
33
Object-Oriented Basics: Messages
 Messages are the mechanism by which objects
(classes) interact.
object: receiver
object: sender
attributes:
attributes:
operations:
operations:
message: [receiver,
operation, parameters]
message: [sender,
return value(s)]
34
Where Are We?
 What is an object?
 Four principles of OO
 What is a class?
 Polymorphism and
generalization
 Organizing model elements
35
What Is Polymorphism?
 The ability to hide many different
implementations behind a single interface.
Manufacturer A
Manufacturer B Manufacturer C
OO Principle:
Encapsulation
Remote Control
36
Example: Polymorphism
Stock Bond Mutual Fund
getCurrentValue()
financialInstrument.getCurrentValue()
getCurrentValue()
getCurrentValue()
37
What Is Generalization?
 A relationship among classes where one
class shares the structure and/or behavior
of one or more classes.
 Defines a hierarchy of abstractions in which
a subclass inherits from one or more
superclasses.
 Single inheritance.
 Multiple inheritance.
 Is an “is a kind of” relationship.
38
Example: Single Inheritance
 One class inherits from another.
Savings Checking
Superclass
(parent)
Subclasses
(children)
Generalization
Relationship
Ancestor
Account
- balance
- name
- number
+ withdraw()
+ createStatement()
Descendents
39
Object-Oriented Basics: Inheritance
 Objects inherit from
the class all attributes
and operations.
class: Furniture
cost
dimensions
weight
location
color
buy
sell
weigh
move
object:
theTable
cost
dimensions
weight
location
color
buy
sell
weigh
move
object:
theChair
cost
dimensions
weight
location
color
buy
sell
weigh
move
40
Example: Multiple Inheritance
 A class can inherit from several other
classes.
Use multiple inheritance only when needed and
always with caution!
FlyingThing Animal
Airplane Helicopter Bird Wolf Horse
Multiple Inheritance
41
What Is Inherited?
Inheritance leverages the similarities among classes.
 A subclass inherits its parent’s attributes,
operations, and relationships.
 A subclass may:
 Add additional attributes, operations,
relationships.
 Redefine inherited operations. (Use caution!)
 Common attributes, operations, and/or
relationships are shown at the highest
applicable level in the hierarchy.
42
Where Are We?
 What is an object?
 Four principles of OO
 What is a class?
 Polymorphism and
generalization
 Organizing model elements
43
 A general purpose mechanism for
organizing elements into groups.
 A model element that can contain other
model elements.
 A package can be used:
 To organize the model under development.
 As a unit of configuration management.
What Is a Package?
University
Artifacts
44
A Package Can Contain Classes
 The package, University Artifacts, contains
one package and five classes.
University
Artifacts
CourseOffering
Schedule
Professor
Course
Student
Student
Artifacts
45
Diagram Depiction
<heading>
<contents area>
 Each diagram has a frame, a heading
compartment in the upper left corner, and a
contents area.
 If the frame provides no additional value, it may
be omitted and the border of the diagram area
provided by the tool will be the implied frame.
46
Review
 What is an object?
 What are the four principles of object
orientation? Describe each.
 What is a class? How are classes
and objects related?
 What is an attribute? An operation?
 Define polymorphism. Provide an
example of polymorphism.
 What is generalization?
 Why use packages?
47
Applying UML and Patterns in OOA/D
 Skills in object-oriented analysis and design (OOA/D) are
essential for the creation of well-designed, robust, and
maintainable software using object technologies and
languages such as Java, C++
What these skills are:
 Design Patterns - named problem-solution formulas that
codify exemplary design principles.
 They are best-practice principles to help us answer design
questions:
 Class Design - How to Assign Responsibilities to Classes?
How should classes interact? What classes should do what?
 UML - The UML is not OOA/D or a method, it is simply
notation.
48
Assign Responsibilities
 Fundamental ability in OOA/D is to skillfully assign
responsibilities to software components - classes
 Nine fundamental principles in object design and
responsibility assignment will be introduced later.
 OK, wait until we see them…
49
What Is Analysis and Design?
 Analysis
emphasizes an investigation of the
problem
and requirements
itresunqm
, rather than a
solution
"Analysis" is a broad term, best qualified, as in
requirements analysis
r eq u i r em en t s an al ysi s
(an investigation of the
requirements) or object analysis
o b j ect an al ysi s
(an investigation
of the domain objects).
 Design
emphasizes a conceptual solution
iltacsnou that
fulfills
the requirements
itreshu , rather than its
implementation.
50
Object-Oriented Processes: Analysis
 Define all classes (and relationships and behavior
associated with them) that are relevant to the
problem to be solved.
 Tasks:
 Communicate basic user requirements to SWE
 Identify classes (attributes & methods defined)
 Specify class hierarchy
 Represent object-to-object relationships
 Model object behavior
51
Object-Oriented Processes: Analysis Approaches
 Booch
 Coad & Yourdon
 Jacobson
 Rumbaugh
 Wirfs-Brock
 Formal Methods UUnniiffiieedd MMeetthhoodd
FFuussiioonn
52
Object-Oriented Processes: Design
 Transform the analysis model (created using OOA)
into a design model that serves as a blueprint for
software construction.
 Phases:
 High-level — (sub)system design phase
 Low-level — object design phase
53
Object-Oriented Processes: Design Goals
 Describe characteristics of the subsystems
required to implement customer requirements and
the needed support environment.
 OOD enables a software engineer to
 indicate the objects that are derived from each
class
 how these objects interrelate with one another
 OOD depicts how
 relationships among objects are achieved
 behavior is to be implemented
 communication among objects is to be
implemented
54
Review: What is OOA/D
 Object-oriented analysis
is about finding and describing
the objects—or concepts—in the problem domain
 object-oriented design
is about defining software
objects and how they collaborate to fulfill the
requirements.
B o o k
t i t l e
public class Book
{
private String title ;
public Chapter getChapter (i n t )
{. . . }
}
domain concept
visualization
of domain
concept
representation in an
object -oriented
programming language
55
Procedural vs Object-Oriented
 Instead of programming the computer to do
calculation (in mathematical functions), OO
programming attempts to model interacting
components
to build a solution.
 In similar ways, traditional structured ISAD also
differs from OOAD.
56
Structured ISAD vs OOAD
• Structured ISAD
– functional decomposition
• OOAD
– object decomposition: discover the
objects, and assign proper responsibilities
ircsntspi

57
An Simple Example
 We will design a simple program by going through
the basic OOAD steps to demonstrate how to
OOAD in short.
 Example – Design a small program to simulate a
"dice game" in which a player rolls two die. If the
total is seven, they win; otherwise, they lose.
58
Define Use Cases
 Requirements analysis may include a description of related
domain processes, these can be written as use cases.
 Use Cases are a popular tool in requirements analysis to
capture the functional aspects of requirements
 Use cases are not an object-oriented
 There are different ways to write Use Cases. Here, we use
a narrative statement method - simply written stories. More
methods will be introduced later.
Use case: Play a Dice Game
A player picks up and rolls the dice. If the dice face
value total seven, they win; otherwise, they lose.
59
Define a Domain (Analysis) Model
 Object-oriented analysis
is concerned with creating a
description of the domain from the perspective of
classification by objects – expressed as a domain model.
 Domain model
 Defining a domain model involves identifying:
concepts,
attributes,
associations
. Player
nam e
DiceGame
D ie
faceValue
R o lls
P la ys
Includes
2
2
1
1
1
1
60
Define Interaction Diagrams
 Object-oriented design is concerned with defining software
objects and their collaborations.
 A common notation to illustrate these collaborations is the
interaction diagram.
 It shows the flow of messages between software objects, and thus
the invocation of methods.
:D iceGame
play()
die1 : D ie
fv1 := getFaceValue()
die2 : D ie
roll()
roll()
fv2 := getFaceValue()
61
Define Design Class Diagrams
 Interaction diagrams
gives a dynamic
d y n a m i c
view
of
collaborating objects
 It is useful to create a static
s t a t i c
view
of the class definitions
with a design class diagram i
n addition to interaction
diagrams
2
D ie
faceValue : int
getFaceValue() : int
roll()
DiceGame
die1 : Die
die2 : Die
play()
1

标签:What,Object,objects,Introduction,object,Part,OOAD,model,class
From: https://blog.51cto.com/u_696257/6151506

相关文章