Professional Documents
Culture Documents
Lecture 2
© Lethbridge/Laganière 2005
What is UML?
• UML (Unified Modeling Language)
• Nonproprietary standard for modeling software systems, OMG
• Information at the OMG portal http://www.uml.org/
• Commercial tools: Rational (IBM),Together (Borland), Visual
Architect (business processes, BCD)
• Open Source tools: ArgoUML, StarUML, Umbrello,
• Online tools, look at this list: http://modeling-
languages.com/web-based-modeling-tools/
• We will use umple umple.org
3
UML: First Pass
4
UML First Pass
• Class diagrams
• Describe the static structure of the system: Objects,
attributes, associations
• Sequence diagrams
• Describe the dynamic behavior between objects of the
system
• Statechart diagrams
• Describe the dynamic behavior of an individual object
• Activity diagrams
• Describe the dynamic behavior of a system, in particular
the workflow.
5
UML Core Conventions
© Lethbridge/Laganière 2005
6
UML first pass: Class diagrams
Association
Class
Multiplicity
SimpleWatch
1 1 1 1
2 1 2 1
PushButton Display Battery Time
Association
Class
Multiplicity Watch
1 1 1 1
2
1 2 1
PushButton
state LCDDisplay Battery Time
push()
blinkIdx Load Now
release() blinkSeconds()
blinkMinutes()
blinkHours()
stopBlinking()
referesh() Operations
Attribute
8 © Lethbridge/Laganière 2005
UML first pass: Sequence diagram
Actor Message Object Lifeline
pressButton1() blinkHours()
pressButton1()
blinkMinutes()
pressButton2()
incrementMinutes()
refresh()
pressButton1and2()
commitNewTime()
stopBlinking()
Activation
button1&2Pressed button2Pressed
Blink Increment
Hours Hours
Transition button1Pressed
button1&2Pressed button2Pressed
Blink Increment
Minutes Minutes
State
button1Pressed
button2Pressed
Stop Blink Increment
Blinking Seconds Seconds
Final state
Represent
10
behavior of a single object with interesting dynamic behavior.
© Lethbridge/Laganière 2005
UML first pass: Activity diagrams
https://www.ibm.com/developerworks/rational/library/2802.html
Represent
11
the dynamic behavior of the system (the workflow).
What is Object Orientation?
Procedural paradigm:
• Software is organized around the notion of procedures
• Procedural abstraction
• Works as long as the data is simple
© Lethbridge/Laganière 2005
What is Object Orientation?
© Lethbridge/Laganière 2005
Object Oriented paradigm
© Lethbridge/Laganière 2005
https://www.alphansotech.com/procedural-vs-object-oriented-programming
© Lethbridge/Laganière 2005
A View of the Two paradigms
© Lethbridge/Laganière 2005
Classes and Objects
Object
• A chunk of structured data in a running software system
• Has properties
• Represent its state
• Has behaviour
• How it acts and reacts
• May simulate the behaviour of an object in the real world
© Lethbridge/Laganière 2005
Objects
© Lethbridge/Laganière 2005
similar objects, its in
behavior are instances
Classes For example, Figure
from Figure 2.2 can be
Employee declares that a
A class: a position.
• A unit of abstraction in an object oriented (OO) program
As a software modul
including:
© Lethbridge/Laganière 2005
Is Something a Class or an Instance?
© Lethbridge/Laganière 2005
Naming classes
© Lethbridge/Laganière 2005
similar objects, its in
behavior are instances
Variables For example, Figure
from Figure 2.2 can be
Employee declares that a
Variables defined inside a class corresponding to data present
a position .
in each instance
• Also called fields or member variables
• Attributes Employee
• Simple data
• E.g. name, dateOfBirth name
dateOfBirth
address
position
As a software modul
including:
© Lethbridge/Laganière 2005
Variables vs. Objects
A variable
• Refers to an object
• May refer to different objects at different points in time
Type of a variable
• Determines what classes of objects it may contain
© Lethbridge/Laganière 2005
Class variables
• If one instance sets the value of a class variable, then all the other instances see the
same changed value.
© Lethbridge/Laganière 2005
Organizing Classes into Inheritance
Hierarchies
Superclasses
• Contain features common to a set of subclasses
Inheritance hierarchies
• Show the relationships among superclasses and subclasses
• A triangle shows a generalization
Inheritance
• The implicit possession by all subclasses of features defined in its superclasses
© Lethbridge/Laganière 2005
An Example Inheritance Hierarchy
© Lethbridge/Laganière 2005
Polymorphism
© Lethbridge/Laganière 2005
Polymorphism
© Lethbridge/Laganière 2005
The Isa Rule
© Lethbridge/Laganière 2005
Why Java?
30
Java, Web, and Beyond
© Lethbridge/Laganière 2005
Java’s History
http://www.java.com/en/javahistory/index.jsp
© Lethbridge/Laganière 2005
Java documentation
© Lethbridge/Laganière 2005
Characters and Strings
© Lethbridge/Laganière 2005
Arrays and Collections
© Lethbridge/Laganière 2005
Casting
© Lethbridge/Laganière 2005
Exceptions
© Lethbridge/Laganière 2005
Interfaces
© Lethbridge/Laganière 2005
Packages and importing
© Lethbridge/Laganière 2005
Access control
© Lethbridge/Laganière 2005
Programming Style Guidelines
© Lethbridge/Laganière 2005
Programming style …
Comment extensively
• Comment whatever is non-obvious
• Do not comment the obvious
• Comments should be 25-50% of the code
© Lethbridge/Laganière 2005
Programming style …
© Lethbridge/Laganière 2005
Programming style ...
© Lethbridge/Laganière 2005
Implicit Import and Explicit Import
No performance difference
© Lethbridge/Laganière 2005