OO programming and UML Design - PowerPoint PPT Presentation

1 / 70
About This Presentation
Title:

OO programming and UML Design

Description:

The structure and behaviour of similar objects are defined in their common class ... The class interface is its external (public) view ... – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 71
Provided by: zji
Learn more at: https://www.cs.wcupa.edu
Category:

less

Transcript and Presenter's Notes

Title: OO programming and UML Design


1
OO programming and UML Design
  • Dr. Zhen Jiang
  • West Chester University
  • E-mail zjiang_at_wcupa.edu

2
Outline
  • Introduction to object and class
  • Introduction to UML
  • Introduction to UML design

3
Introduction to object and class
  • Whats object
  • Identity
  • State
  • Behavior
  • Sequence Diagram
  • Statechart Diagram
  • Messages and methods
  • Whats class
  • Objects and Classes
  • Class Attributes
  • Operation (Method)
  • Interfaces
  • Interfaces and Implementation

4
Whats object
  • Fundamentals of Object-Oriented Programming

5
Whats object
  • Conceptually, there are many ways to think of an
    object
  • something that can be seen or touched
  • a thing to which some action is directed
  • something that performs an action
  • The structure and behaviour of similar objects
    are defined in their common class
  • Objects have three properties identity , state,
    and behaviour

6
Object Property 1 Identity
  • Identity is that property of an object which
    distinguishes it from all other objects
  • Most programming languages use variable names to
    refer to objects
  • Keep in mind, however, that an object may not
    have a name Similarly, an object might have
    multiple names (aliases)
  • For this reason, there is a subtle distinction
    made between the concepts of "name" and "identity"

7
Object Property 2 State
  • The state of an object encompasses all of the
    descriptions of the object plus the current
    values of each of these descriptions

8
Object Property 3 Behaviour
  • Behaviour is how an object acts and reacts, in
    terms of its state changes and message passing
  • The state of an object represents the cumulative
    results of its behaviour
  • In object-oriented programming, a behaviour is
    invoked by sending a message to an object

9
Sequence Diagrams
  • A sequence diagram is an interaction diagram that
    focuses on the time ordering of messages
  • A vertical dashed line is used to represent the
    lifetime of an object (its the objects
    lifeline)
  • A focus of control is a tall, thin rectangle that
    shows the period of time during which an object
    is performing an action

10
ATC
Radar
Pilot
requestLdgClearance(r)
checkWeather
checkRunwayClear(r)
clear
clearance
11
Sequence
12
Statechart Diagram
  • Captures dynamic behavior (event-oriented)
  • Purpose
  • Model object lifecycle
  • Model reactive objects (user interfaces, devices,
    etc.)

13
(No Transcript)
14
Example Objects
  • There are many physical objects we can examine
    right in this room
  • each person is an object
  • any chair is not an object
  • each light bulb is an object
  • Any book is not an object
  • this room itself is an object (full or not)

15
  • See if the followings are objects or not
  • Desk
  • Lamp
  • Person
  • Log
  • The Earth
  • Clock
  • Machine
  • Computer
  • Saving account
  • Answer N, Y, Y, N, Y, Y, Y, Y, Y

16
Messages and Methods
  • A object executes a method when it sends/receives
    a message
  • For example, we can ask/tell a dog to sit by
    sending him the message "sit"
  • In object-oriented programming, objects send
    messages asking/telling others to perform
    behaviours -- those other objects invoke the
    method corresponding to the message in order to
    execute the desired behaviour

17
Whats class
  • A class describes the common structure
    (attributes/state) and behaviour of its instances
  • For example,
  • 3.14, 2.71, and 5.5 can be classified as Floats
  • the following shapes can be classified as Circles

18
Classes and Objects
  • An object is called an "instance" of a class
  • The terms instance and object are interchangeable
  • Creating an object from a class is often called
    instantiation
  • For example, there are many person objects in
    this room -- each person is an instance of the
    person class

19
Classes and objects
  • How would we describe the state, behaviour, and
    identity for each of these objects
  • We have looked at objects and we have seen that
    objects can be "classified" into classes
  • As programmers, we work with both classes and
    objects from those classes
  • For example, we might write a stack class and
    create multiple stack objects for use in our
    program

20
  • In a 2D drawing package, circles have a radius, a
    line thickness, a line colour, and a fill colour
  • Each individual circle (instance) drawn by the
    user has its own value for each attribute
  • The programmer writes a Circle class and the
    program instantiates a Circle object every time
    the user draws a Circle

a snowman made from 9 Circle instances
21
Class Attributes
  • An attribute is a named property of a class that
    describes the range of values that instances of
    the property may hold.(Booch,1999)
  • An attribute has a type that defines the type of
    its instances.
  • Only the object itself should be able to change
    the value of its attributes.
  • The values of the attributes define the state of
    the object

22
Operation (Methods)
  • An operation is the implementation of a service
    that can be requested from any object of the
    class to affect behavior (Booch, 1999)
  • An operation can be
  • Question (does not change the value of the
    object)
  • Command (may change the value of the object)

23
Interfaces
  • An interface is a collection of operations that
    are used to specify a service of a class or a
    component (Booch, 1999)
  • An interface is a contract of related services
    and a set of conditions that must be true for the
    contract to be faithfully executed
  • Interfaces formalize polymorphism, they allow us
    to define polymorphism in a declarative way
    unrelated to implementation

24
Interface and Implementation
  • The class interface is its external (public) view
  • The class implementation is its internal
    (private) view
  • It is convenient to think of the interface as
    describing "what the objects of this class can
    do" and the implementation as "how the objects of
    this class do it"
  • The implementation of a class consists of all the
    "behind the scenes" operations defined in the
    interface of the class

25
Introduction to UML
  • Whats UML
  • Goals of UML
  • Overview
  • Class diagram
  • Introduction
  • Class icon
  • Class relationship
  • Constraints
  • Other diagrams

26
UML Unified Modeling Language
  • The Unified Modeling Language (UML) is an
    industry-standard language for specifying,
    visualizing, constructing, and documenting the
    artifacts of software systems
  • The UML definition was led by Grady Booch, Ivar
    Jacobson, and Jim Rumbaugh (all now at Rational
    Software)

27
  • UML simplifies the process of software design,
    making a "blueprint" for construction

In Essence a tool used through the analysis and
design phases of system development for
expressing the constructs and relationships of
complex systems
Target Usage for building object-oriented and
component-based systems
28
Goals of UML
1. Provide users with a ready-to-use, expressive
visual modeling language so they can develop and
exchange meaningful models 2. Provide
extensibility and specialization mechanisms to
extend the core concepts. 3. Be independent of
particular programming languages and development
processes. 4. Provide a formal basis for
understanding the modeling language. 5.
Encourage the growth of the Object-Oriented tools
market. 6. Support higher-level development
concepts such as collaborations, frameworks,
patterns and components. 7. Integrate best
practices.
29
  • Many free learning materials on the web
  • e.g. www.rational.com/uml
  • Standard of UML
  • www.cs.wcupa.edu/zjiang/01-09-67.pdf
  • Some recommended texts on UML
  • The Unified Modeling Language User Guide, G.
    Booch, J. Rumbaugh, I. Jacobson, 2000
  • UML Explained, Kendall Scott, 2001
  • Applying UML and Patterns 2nd Ed., Craig Larman,
    2002
  • UML Distilled 2nd Ed., Martin Fowler with K.
    Scott, 2000
  • UML and C, R. Lee W. Tepfenhart, 2001

30
UML Overview
  • UML is a language for visualizing, specifying,
    constructing and documenting the artifacts of a
    software system
  • The artifacts might include requirements,
    architecture, design, source code, project plans,
    tests, prototypes, releases

31
Review
something
Object
action
action
state1
state2
operations/methods
attributes attribute1,
attribute2
structure
operation/method
attribute1
attribute2
value
32
Light
Turn on/off
On
Off
operations/methods
Turn_on/off ( )
attributes True, False
structure
Turn_on
True
False
value
Turn_off
33
Class Diagram
  • Introduction
  • Class Icon
  • Relationships
  • Constraints

34
Introduction
  • The class diagram is fundamental to
    object-oriented programming
  • UMLs class diagrams capture the attributes and
    operations of each class as well the
    relationships that exist between classes

35
Class Icon
  • Class Icon
  • Hiding Details
  • Visibility Notation
  • Attribute Specification
  • Operation Specification

36
Class Icon
  • The UML class icon is a rectangle with three
    compartments
  • class name
  • class attributes
  • class operations
  • Attributes are specified in the following form
  • objectclass name

Circle
radius float center_x int center_y int
area() display()
37
Hiding Detail
  • You can optionally leave out the attributes,
    operations, or both in a class icon

Circle

area() display()
Circle
radius float center_x int center_y int
Circle
38
UML Member Visibility Notation
  • UML has three visibility prefixes for members
    for public, for protected, and for private
  • e.g.

Circle
-radius float
area() display()
39
Full UML Attribute Specification
  • The full form of a UML attribute is as
    followsvisibility name multiplicity
    type initial value property
  • The property choices are changeable, addOnly, and
    frozen

Student Info
-id string -hasGraduated bool false
40
Full UML Operation Specification
  • The full form of a UML operation is as
    followsvisibility name (parameter-list)
    return-type property
  • The property choices are sequential, concurrent,
    guarded, and isQuery
  • The full form of a UML parameter isdirection
    name type default-value
  • The direction choices are in, out, and inout

41
UML Class Relationships
  • A class relationship is a connection between two
    (or more) classes
  • The three most important class relationships are
    generalizations, associations, and aggregations
  • UML provides a graphical representation for each
    of the relationships using a different line type
    for each relationship

42
Class Relationships
  • Generalization
  • Association
  • Association Class
  • Qualified Association
  • Ternary Association
  • Aggregation

43
Generalization
  • A generalization is a relationship between a
    general thing (superclass) and a more specific
    kind of that thing (subclass)
  • In the UML, generalization requires that objects
    of the subclass may be used anywhere an object of
    the superclass appears

Person
Student
44
Association
  • An association is a structural relationship that
    specifies that objects of one thing are connected
    to objects of another

Faculty
Student
45
Association
  • Associations can be adorned with a name.

Teaching
Faculty
Student
46
Association
  • Associations can be adorned with the roles.

teacher
Faculty
Student
learner
47
Association
  • Associations can be adorned with the
    multiplicity.

Faculty
Student
4..
1
48
Association Class (relation attributes)
  • Each object of association class is one instance
    of relationship (link) in an association.

1..
Faculty
Student
4..
Course
49
Qualified Association
  • Qualified association relates two classes and a
    qualifier.
  • The qualifier is a special attribute that reduces
    the effective multiplicity of an association.

Directory
File
file name
50
Ternary Association
  • A ternary association is a structural
    relationship that specifies that objects of one
    thing are connected to objects of other twos.

Language
Project
Developer
51
Aggregation
  • An aggregation is an association that represents
    whole/part relationship
  • The whole end of the association relationship
    is adorned with an open diamond shape (e.g. X is
    part of Y)
  • e.g. doorDoor is part of carCar

X
Y
52
Generalization, Aggregation, and Association
  • See if the following pairs of classes have
    generalization, aggregation or association
  • Faculty student (as)
  • Hospital doctor (as)
  • Door Car (ag --ltgt)
  • Member Organization (ag --ltgt)
  • People student (ge lt-- )
  • Circle point (ge --gt)
  • Department Faculty (as)
  • Employee Faculty (ge lt--)
  • Item Printer (ge lt--)
  • Account Checking account (ge lt-- )

53
Constraints
  • Constraints on Object
  • Constraints on Relations (Ordering)
  • General Constraints (Dependency)

54
UML class diagram is not object diagram
Customer
Loan
Bank
Bank-Loan
Other-Loan
55
Constraints on Object
  • The constraints restricts the values that objects
    can be.
  • Example No employees salary can exceed the
    salary of the employees boss.

salary ltboss.salary
Employee Salary
Employer Salary
56
Constraints on Relations (Ordering)
  • Order indicates that the elements of the many
    end of an association have an explicit order that
    must be preserved.

ordered
Paper
Author
1
1..
57
General Constraints (Dependency)
  • A dependency is a using relationship that states
    that a change in specification of one thing may
    affect another thing that uses it (but not
    necessarily the reverse)

58
General Constraints (Dependency)
  • Dependencies are often used when one class uses
    another class as an argument of the operation
  • Dependencies are also often used to express
    general constraints.

Aerodrome
checkRVR( r Runway )
Runway
member-of
Person
Committee
subset
chair-of
59
UML Design
  • UML class diagram is not object diagram.
  • How to describe the behaviors/actions of objects
    in UML class diagram?
  • UML class diagram is not data flow chart.
  • What kind of relationship is generalization?
  • How to keep the consistency of all the
    constraints?

60
UML class diagram is not object diagram
  • Should we add relation between Bank and
    Other-Loans?
  • Can Bank change Other-loans?
  • Instance of Loan and Other-Loans?

Other-Loan
Customer
Bank
Loan
61
How to describe the behaviors/actions of objects
in UML class diagram
?
Person
Based on Use Case analysis
sSN address email
Student
Casher
Faculty
Customer
62
How to describe the behaviors/actions of objects
in UML class diagram
  • Use case (stories) Each use case defines an
    interaction between an actor and the system

Use case
Use case
System
Use case
Use case
63
Reception
  • Scenarios of a use case

Check
?
Order
Waiting
Failure
Authorized
Success
Failure
64
How to describe the behaviors/actions of objects
in UML class diagram
  • Basic idea
  • behaviors interface
  • For details, see in www.cs.wcupa.edu/zjiang/int
    ro_uc.ppt.

65
UML class diagram is not data flow chart
bargain
Customer
Dealer
sign
buy
sell
report
Product
Manager
authorize
66
UML class diagram is not data flow chart
  • Customer, Dealer, and Manager
  • Bargain

Product
Customer
Salesman
Dealer
Manager
67
What kind of relationship is generalization
x int y int
Position
Point
Position
Point
People
?
Student
radius double
Rectangle
Circle
Tip 4 Class A is a super class of class B if
and only if any object of class B can also play
the role as an object of class A.
68
How to keep the consistency of all the constraints
1
1..6
Ticket-buyer
Traveler
1
1
0..6
Dependent
1
69
How to keep the consistency of all the constraints
0..1
0..1
Ticket-buyer
Traveler
1
1
0..6
Dependent
0..1
70
How to keep the consistency of all the constraints
Traveler
0..1
1
0..6
Ticket-buyer
Dependent
Write a Comment
User Comments (0)
About PowerShow.com