Building Blocks of UML
Outline
- Unified Modeling Language
Object-Oriented Modeling
- Principles and Concepts • Modeling Relations and Structures • Modeling Relations and Structures oleh:
- Modeling Dynamic Behavior
I Gede Made Karma
- Modeling Requirements with Use Cases
Object-Oriented Modeling Using UML
2 What is a Model? Why We Model
“A successful software organization is A model is a simplification of reality. one that consistently deploys quality A model may provide software that meets the needs of its
- – blueprints of a system blueprints of a system
users. An organization that can A i ti th t
- – Organization of the system
develop such software in a timely and
- – Dynamic of the system
predictable fashion, with an efficient and effective use of resources, both human and material, is one that has sustainable business.”
Object-Oriented Modeling Using UML
3 Object-Oriented Modeling Using UML
4 Why We Model Why We Model
- Model is buil
- We build models so that we can see
- – Communicate the desired structure and
and better understand the system we behavior of the system are developing. p g
- – Visualize and control the system’s architecture Vi li d t l th t ’ hit t
- – Better understand the system that being built
- – Manage risk
- – Expose opportunities for simplification and reuse
Object-Oriented Modeling Using UML
5 Object-Oriented Modeling Using UML
6 Principles of Modeling
- The choice of what models to create has a major influence on how a problem is approached and how a solution is shaped.
- Every model may be expressed at
- Models help us
- – to visualize a system as it is or as we want it to be.
- – to specify the structure or behavior of a system.
- – in providing a template that guides us in constructing a system.
- – in providing documenting the decisions we have made.
- The best models are connected to reality.
- No single model is sufficient. Every nontrivial system is best approached through a small set of nearly independent models.
Object-Oriented Modeling Using UML
12
Object-Oriented Modeling Using UML
Principles and Concepts
11
Object-Oriented Modeling Using UML
Building Blocks of UML
10 Specifying
What is UML?
- Two most common ways in modeling software systems are
- UML is a language for
- – Visualizing – Specifying
- – Algorithmic
- Procedures or functions
- – Constructing – Documenting
- – Object oriented
- Objects or classes
Object-Oriented Modeling Using UML
Objected-Oriented Modeling
8 y y p different levels of precision.
Object-Oriented Modeling Using UML
7
f h b h f Object-Oriented Modeling Using UML
Importance of Modeling
9 Algor thm c
- Things -- abstraction
- Relations -- tie things together
- Diagrams group interesting
- Objects and Classes • Principles
- Diagrams -- group interesting collections of things
- The state of an object is composed of a set of fields (data fields), or attributes.
- Each field has a name, a type, and a value.
- Each method has a name, a type, and a value.
- Each method may or may not return a value.
- Features are a combination of the state and the behavior of the object.
- Two objects are equal if their states are equal.
- Two objects are identical if they are the same objects.
- A class defines a template for creating or instantiating its instances or objects.
- A class is a description of a set of objects that share the same attributes, operations, relationships, and semantics.
- Methods that do not modify the state of the object are called accessors.
- Methods that modify the state of the object are called mutators.
- Objects can be mutable or immutable.
- A class defines --
- – the names and types of all fields
- – the names, types, implementations of all methods
- The values of the fields are not defined or fixed in the class definition.
- Each instance of the class has its own state.
- Different instances of the class may have different states.
- The implementations of methods are defined in the class definition and fixed for a given object.
- Values of methods are immutable
(int dx, int dy){ // implementation
18 p
Object-Oriented Modeling Using UML
Class name: Point class Point { Fields: x, y int x, y; Method: move public void move
Example
17 • The values of the fields are mutable.
Object-Oriented Modeling Using UML
Classes
j
16
Object-Oriented Modeling Using UML
Classes
15 j • The values of the fields are mutable.
Object-Oriented Modeling Using UML
Properties of Objects
f m , yp , • Behaviors are defined by methods.
14
Object-Oriented Modeling Using UML
Objects • Each of object has a unique identity.
A class characterizes the structure of states and behaviors that are shared by all instances.
A class represents a set of objects with similar characteristics and behavior. This objects are called the instances of the class.
Class
13 y
Object-Oriented Modeling Using UML
An object has an identity, a state, and a behavior.
An object is a thing that can be distinctly identified.
Objects and Classes Interpretation in the Real World Interpretation in the Model Object
}
- The name of the field is required in the field declaration.
- Field declaration may include:
Private Student students[0..MAX_Size]
21
protected protected # package ~ private private -
Examples
Java Syntax UML Syntax Object-Oriented Modeling Using UML
22 Date birthday Birthday:Date
Public int duration = 100 +duration:int = 100
Method Declaration
Visibility syntax in Java and UML Visibilty Java Syntax UML Syntax public public +
Object-Oriented Modeling Using UML
[Visibility][Type]Name([Parameter, ...]) [Visibility]Name([Parameter, ...])[:Type]
Examples
Java Syntax UML Syntax Object-Oriented Modeling Using UML
24
void move(int dx, int dy) ~move(int dx, int dy) public int getSize() +int getSize()
Object-Oriented Modeling Using UML
[Visibility]Name[[Multiplicity]][:Type][ InitialValue]
1 The middle compartment
- Visibility or accessibility defines the scope:
- – Public -- the feature is accessible to any class
- – Protected -- the feature is accessible to the class itself, all the classes in the same package, and all its subclasses.
- – Package -- the feature is accessible to the class itself and all classes in the same package.
- – Private -- the feature is only accessible within the class itself.
20
UML Notation for Classes
ClassName The top compartment shows the class name. field
Object-Oriented Modeling Using UML
19
1
… field
n
The middle compartment contains the declarations of the fields of the class. method
1
… method
m
The bottom compartment contains the declarations of the methods
Field Declaration
[Visibility][Type]Name[[Multiplicity]][=InitialValue] [Visibility]Name[[Multiplicity]][:Type][=InitialValue]
Object-Oriented Modeling Using UML
- students[0..MAX_Size]:Student
- The name of the method is required in the method declaration.
- Method declaration may include:
- Each parameter of a method can be specified by -- Type Name
23 Method declaration may include:
- x:int
- y:int Object-Oriented Modeling Using UML
- move(dx:int,dy:int)
Object-Oriented Modeling Using UML
Object-Oriented Modeling Using UML
Java.awt.event javax.swing.*
Packages
Method move() Arguments (10,20)
29 p1.move(10,20)
Recipient p1 Object-Oriented Modeling Using UML
Example
to an object -- recipient
28 A message represent a command sent
Object-Oriented Modeling Using UML
Message Passing or Method Invocation
P1.y = 40;
27 y = 0 P1.y = 0; P1:Point Point p1 = new Point(); x = 24 y = 40 p1.x = 24;
P1:Point Point p1 = new Point(); x = 0 p1.x = 0; P1
Examples
The bottom compartment contains a list of the fields and their values. objectName -- objectName whose class is of no interest :ClassName -- anonymous object of ClassName which can be identify only through its relationship with other object.
= value n
1 … field n
1 = value
field
26
1 Object-Oriented Modeling Using UML
1 = value
UML Notation for Object ObjectName : ClassName The top compartment shows the object name and its class. field
Point x y move()
25 private int x private int y public void move(int dx,int dy)
Point Point
Example
- Objects communicate with one another through message passing.
- A message represent a command sent
- A message consists of the receiving object, the method to be invoked and the arguments to method.
- Package name are in lower case --
- Packages that will be widely used should be named as the reverse of the internet domain as the prefix of the package name -
- EDU.emporia.mathbeans.MathTable EDU.emporia.mathtools.*
30 UML notation of packages
- Modularity:
- – alleviate complexity of large-scale systems
- Abstraction:
- – separating the essential from the non-essential
- Encapsulation:
- – Information hiding
- Polymorphism:
- – Portability
- Levels of Abstraction:
- – Organization of classes and interfaces
p g characteristics of an entity
Object-Oriented Modeling Using UML
Object-Oriented Modeling Using UML
32
31 Principles
Principle of Modularity
Object-Oriented Modeling Using UML
33 coupling.
Principle of Abstraction
- A complex software system should be decomposed into a set of highly cohesive but loosely coupled modules.
- The basic for decomposition are cohesion and
- The behaviors or functionalities should be precisely characterized as contractual interface which captures
- – Cohesion -- functional relatedness of the entities within modules.
- – Coupling – inter-dependency among different modules.
- The complexity of the module is hidden from the clients.
- Each module is relatively small and simple
- Interactions among modules are relatively simple
- hierarchical
- The implementation of a module should be separated from its contractual interface and hidden
- Ability to interchange modules dynamically without affecting the system.
- refers to a contractual interface with multiple interchangeable implementation
- Information hiding
34
p the essence of the behavior.
Principle of Encapsulation
Object-Oriented Modeling Using UML
35 from the clients of the module.
Principle of Polymorphism
Object-Oriented Modeling Using UML
36
y
Object-Oriented Modeling Using UML
- Define a relationship among classes and interfaces
- Inheritance model -- the is-a(n) relationship
- A class diagram consists of
- – A set of nodes that represent classes and interfaces A t f li k t l ti hi
- – A set of links represent relationships among classes
- Class diagrams can be used to model:
- – Inheritance -- extension and implementation
- – Association -- aggregation and compostion
- – Dependency
Object-Oriented Modeling Using UML
Object-Oriented Modeling Using UML
1
1
Faculty advisee adviser
41 Student Course
Object-Oriented Modeling Using UML
Association
40 Higher level is more general
Abstraction
- Abstractions can be organized into different levels.
- Higher level is more general
- Aggregation is a special form of association
- Association represents binary relationship between classes
- – Has-a or part-whole relationship
- Composition is a stronger form of aggregation
- enroll teach
- enroll *
- Aggregation and Compositon
- Dependency is a relationship between entities such that the proper operation of one entity depends on the presence of the other entity and
39 Principle of Levels of
Object-Oriented Modeling Using UML
relationship Example
38
Object-Oriented Modeling Using UML
Inheritance
37
Object-Oriented Modeling Using UML
Modeling Relationships and Structures
42 gg g
2 Graphical notations
Example Registrar CourseSchedule
exit/Action
1
[Event-List][[Guard]][/Action]
48 p
Object-Oriented Modeling Using UML
47 Modeling Dynamic Behavior
46 Example Object-Oriented Modeling Using UML
Object-Oriented Modeling Using UML
Student Modeling Dynamic Behavior
void addCourse(CourseSchedule a, Course c) void removeCourse(CourseSchedule Course findCourse(String title) void enroll(Course c, Student s) void drop(Course c, Student s Course
45
Object-Oriented Modeling Using UML
the presence of the other entity, and changes in one entity would affect the other entity.
44
Object-Oriented Modeling Using UML
1 1 1..* Dependency
1
1
1
1
Faculty Chairman-of Member-of
43 University Department
1 Object-Oriented Modeling Using UML
1
1
Example
- College Student *
- Sequence diagram
- – Depict object interaction by highlighting the time ordering of method invocation
- State diagram
- – Depict the flow of control using the concepts of state and transitions
- – Labels of transitions are in the form:
- Entry action and exit action entry/Action
- Nested state diagram
- – Composite of state diagrams
Object-Oriented Modeling Using UML
Object-Oriented Modeling Using UML
49 Modeling Dynamic Behavior
50 Example Object-Oriented Modeling Using UML
- Use cases describes the externally observable behavior of system functions in the form of interactions between the system to be developed and the external
- Actors may represent roles played by users of the system or other systems.
- Consist of a name and scenarios
- One of scenarios is the main scenario
51
talk Modeling Requirements with Use Cases
52 system to be developed and the external entities -- Actors.
Use Case Diagram
- Consist of:
- – Use cases
- – Actors – Relationships among actors and use cases
Object-Oriented Modeling Using UML
53 p g
Extension relationships among actors
Object-Oriented Modeling Using UML
54
Object-Oriented Modeling Using UML
- Problem requirements
- Program specifications
- Object models
- – Identifying classes
- – Identifying the features of classes -- states and behaviors
- – Identifying relationships among classes – inheritance and interfaces.
- Provide information on the books, CDs, and software
- Provide a functionality for customers registration as well as updating customer’s
- Allow customers to browse and order books, music CDs, and computer software
- Provide a functionality for ordering and shipping
- Provide a functionality for updating inventory
58 registration as well as updating customer s information
System administrator Inventory manager
Acount Process order g
59 Manage
Object-Oriented Modeling Using UML
Logon Customer Manager
Register Shop Manage catalog
Object-Oriented Modeling Using UML
Dependency relationships among use cases
57 Specifications
Object-Oriented Modeling Using UML
Requirements
56 Object models
Object-Oriented Modeling Using UML
55 Case Study: An E-Bookstore
Object-Oriented Modeling Using UML
Catalog Manager