Introduction to UML 1

Similar documents
An Introduction To UML Class Diagrams Classes

UML for C# Modeling Basics

UML: Classes -- Association

UML FOR OBJECTIVE-C. Excel Software

History OOP languages Year Language 1967 Simula Smalltalk

DATA STRUCTURES USING C

11 November

Using UML Part One Structural Modeling Diagrams

Introduction. UML = Unified Modeling Language It is a standardized visual modeling language.

Glossary of Object Oriented Terms

UML Tutorial: Part 1 -- Class Diagrams.

Efficient Data Structures for Decision Diagrams

Object Oriented Design

Java (12 Weeks) Introduction to Java Programming Language

Design and UML Class Diagrams. Suggested reading: Practical UML: A hands on introduction for developers

Structural Design Patterns Used in Data Structures Implementation

Using UML Part Two Behavioral Modeling Diagrams

UML Class Diagrams. Lesson Objectives

Programming and Software Development CTAG Alignments

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Introduction to Programming System Design. CSCI 455x (4 Units)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Curriculum Map. Discipline: Computer Science Course: C++

Umbrello UML Modeller Handbook

Business Process Measures

Case studies: Outline. Requirement Engineering. Case Study: Automated Banking System. UML and Case Studies ITNP090 - Object Oriented Software Design

Graphical Systems Modeling with UML / SysML Class diagrams

Questions? Assignment. Techniques for Gathering Requirements. Gathering and Analysing Requirements

Algorithms, Flowcharts & Program Design. ComPro

Chapter 5 Names, Bindings, Type Checking, and Scopes

Getting Started With UML Class Modeling. An Oracle White Paper May 2007

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

SysML Modelling Language explained

Lecture 12: Entity Relationship Modelling

[1] [2]

CS 111 Classes I 1. Software Organization View to this point:

Symbol Tables. Introduction

Tutorial - Building a Use Case Diagram

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

Basic Programming and PC Skills: Basic Programming and PC Skills:

Design and UML Class Diagrams

Communication Diagrams

Computing Concepts with Java Essentials

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Best of Both Worlds - A Mapping from EXPRESS-G to UML

ATM Case Study OBJECTIVES Pearson Education, Inc. All rights reserved Pearson Education, Inc. All rights reserved.

UML basics. Part III: The class diagram. by Donald Bell IBM Global Services

Data Analysis 1. SET08104 Database Systems. Napier University

Object Oriented Programming. Risk Management

IV. The (Extended) Entity-Relationship Model

PHP Code Design. The data structure of a relational database can be represented with a Data Model diagram, also called an Entity-Relation diagram.

Introduction: Abstract Data Types and Java Review

Java Application Developer Certificate Program Competencies

Unit 2.1. Data Analysis 1 - V Data Analysis 1. Dr Gordon Russell, Napier University

10CS35: Data Structures Using C

IRA 423/08. Designing the SRT control software: Notes to the UML schemes. Andrea Orlati 1 Simona Righini 2

Business Process Redesign and Modelling

Fundamentals of Java Programming

Data Structures Using C++ 2E. Chapter 5 Linked Lists

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Java Software Structures

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

Implementation Aspects of OO-Languages

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Visio Tutorial 1BB50 Data and Object Modeling (DOM) How to make a UML Class Diagram 2004/2005

BCS2B02: OOP Concepts and Data Structures Using C++

A UML Introduction Tutorial

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

LINKED DATA STRUCTURES

CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.

3D Animation of Java Program Execution for Teaching Object Oriented Concepts

Types of UML Diagram. UML Diagrams OOAD. Computer Engineering Sem -IV

3 Development process for multimedia projects

Computer Programming I

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Java Interview Questions and Answers

A technical discussion on modeling with UML 06/11/03 Entity Relationship Modeling with UML

Introduction to Data Structures

Fundamentals of Visual Modeling

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

XV. The Entity-Relationship Model

16 Collection Classes

Managing Variability in Software Architectures 1 Felix Bachmann*

Tool Support for Software Variability Management and Product Derivation in Software Product Lines

Course Code and Name Year - Semester. Number of marks

Chapter 8 The Enhanced Entity- Relationship (EER) Model

C++ INTERVIEW QUESTIONS

Chapter 1 Modeling and the UML

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

Chapter 2: Entity-Relationship Model. E-R R Diagrams

Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types

Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model

COMPUTER SCIENCE. Paper 1 (THEORY)

PES Institute of Technology-BSC QUESTION BANK

Modernized and Maintainable Code. Frank Weil, Ph.D. UniqueSoft, LLC

Transcription:

Introduction to UML 1

UML UML is a visual modelling Language visual --- UML documents are a diagrams. modelling --- UML is for describing systems systems --- may be software systems or domains (e.g. business systems), etc. It is semi-formal The UML definition tries to give a reasonably well defined meaning to each construct. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 2

Classes and Class Diagrams Classes Fields and Operations Association Composition Generalization Interfaces and Abstract Classes 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 3

Classes Classes are specifications for objects Consist of (in the main) A name A set of attributes (aka fields) A set of operations Constructors: initialize the object state Accessors: report on the object state Mutators: alter the object state Destructors: clean up 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 4

Java representation of a class class Student { } Name private long studnum ; private String name ; Attributes public Student( long sn, String nm ) { studnum = sn ; name = nm ; } public String getname() { return name ; } public long getnumber() { return studnum ;} Operations 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 5

UML Representation of a class Note: UML model may contain more info. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 6

Classes in UML UML can be used for many purposes. In software design UML classes usually correspond to classes in the code. But in domain analysis UML classes are typically classes of real objects (e.g. real students) rather than their software representations. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 7

Usage of (software) classes A class C can be used in 3 ways: Instantiation. You can use C to create new objects. Example: new C() Extension. You can use C as the basis for implementing other classes Example: class D extends C { } Type. You can use C as a type Examples: C func( C p ) { C q ; } 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 8

Relationships Between Classes Association Aggregation Composition Dependence Generalization 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 9

Association Relationships Two classes are associated if each instance of one may be associated with instances of the other. Associations are typically named. Associations are often implemented with pointers 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 10

Multiplicity Constraints Each Department is associated with one DepartmentHead and at least one DepartmentMember Each DepartmentHead and DepartmentMember is associated with one Department No constraint means multiplicity is unspecified 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 11

Role names Role names may be given to the ends of an association Only name roles when it adds clarity 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 12

Navagability An arrow-head indicates the direction of navigability. E.g. Given a student object, we can easily find all Sections the student is taking. No arrow-head: means navigability in both directions. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 13

Implementing navigable associations Usually implemented with fields class Student { private List<Section> sections ; } class Department { private DepartmentHead depthead ; } * 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 14

Implementing associations indirectly An association between objects might also be stored outside of the objects class Department { private static Map<Department,DepartmentHead> heads = new<department,departmenthead> HashMap(); } DepartmentHead gethead() { return heads.get(this) ; } 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 15

Aggregation Aggregation is a special case of association. It is used when there is a whole-part relationship between objects. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 16

Composition Composition is a special case of aggregation. Composition is appropriate when each part is a part of one whole the lifetime of the whole and the part are the same. Graphically it uses a solid diamond Student Record Student Number 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 17

Recursive associations Associations may relate an class to itself. The objects of the class may or may not be associated with themselves. (For example, the left and right children of a node would not be that node. But a GraphNode object might be its own neighbour.) 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 18

Associations vs. attributes Both are usually implemented by fields (a.k.a. data members). Use attributes for primitive types such as integer, boolean, char, etc, and pointers to such. Use association (or aggregation) for pointers that point to classes or interfaces. Use composition for data members that are classes. (Not possible in Java). Use composition if the life time of the part is identical to or contained in the lifetime of the whole. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 19

Degrees of belonging Attribute. Lifetime of attribute equals life time of object that contains it. Composition. Lifetime of the part equals or is, by design, nested within the lifetime of the whole. Aggregation. Whole-part relationship, but parts could be parts of several wholes, or could migrate from one container to another. Association. Relationship is not part/whole. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 20

Generalization/Specialization Represents is-a-kindof relationships. E.g. every Chimp is also an Ape. In OO implementation it represents class inheritance: Inheritance of interface and of implementation too. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 21

Interfaces Interfaces are classes that have no associated implementation. I.e. no attributes, no implementations for any operations In UML use either stereotype to indicate an interface, or lollypop 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 22

Realization Classes specialize classes, but realize interfaces. Similar concept, similar notation. (Note dashes) Choice of notations. Diagrams at right are equivalent. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 23

Generalization/Specialization and Realization in Java UML terminology C specializes D C realizes D Java terminology C extends D C implements D class TestCharInput extends TestInput implements CharSource { } 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 24

The Substitution Principle Suppose class C specializes class D or class C realizes interface D Then any properties that should hold true of all D objects should hold true of all C objects. Question: Should Rectangle specialize Square, or should Square specialize Rectangle, or neither should specialize the other? More on this later. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 25

Abstract operations An operation O is abstract in class C if it does not have an implementation in class C. The implementation of the operation will be filled in in specializations of C. abstract class TreeNode { abstract int height() ; } class Leaf extends TreeNode { int height() { return 1 ; } } class Branch extends TreeNode { TreeNode r, l ; int height(){return Math.max( l.height(), r.height ) ; } } 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 26

Abstract in VP In VP classes are made abstract with a checkbox in the specification. Likewise for operations (class must be abstract first). Italics or slanted text indicate abstractness 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 27

Abstract and Concrete classes Classes that have abstract operations can not be instantiated --- since this would mean that there is no implementation associated with one of the object s operations Classes that can not be instantiated are called abstract classes. Classes that can be are called concrete In UML use the <<abstract>> stereotype for abstract classes and operations. Alternatively: The name of the abstract class or operation is in italics. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 28

Dependence A class C depends on class D if the implementation or interface of C mentions D. C extends D or implements D C has a field of type D or pointer to D or array of D C creates a new D C has an operation that has a parameter local variable return type of type D of a pointer to D or an array of D etc. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 29

Dependence Often dependence is implicit in generalization or association relationships. When it is not, you may want to indicate dependence explicitly. Stereotypes and documentation can add detail. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 30

Dependence Dependence relations are important to note because unneeded dependence makes components harder to reuse in another context harder to isolate for testing harder to write/understand/maintain, as the depended on classes must also be understood It is better to depend on an interface than on a class. More on this later. 2003--2009 T. S. Norvell Memorial University Slide set 2. Slide 31

More on Associations 32

Association Classes Sometimes associations need attributes themselves. An employment relationship between an employer and employee might have a employee number associated with it. 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 33

set, bag, ordered, and sequence In math a A set is an unordered collection without duplication A bag is an unordered collection with possible duplication An ordered set is an ordered collection without duplication A sequence is an ordered collection with possible duplication duplication order set bag ordered set sequence 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 34

set, bag, ordered, and sequence By default, pairs are associated only once. Thus means that, while each employer can have many employees, each employee has only one employment link with each employer. Thus each employee can only have one employee number. Each employer has a set of employees. We can emphasise this point with an annotation: {set} 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 35

set, bag, ordered, and sequence Now consider this association It implies (incorrectly) that a student can only have one enrolment per university!. (Remember the {set} is the default.) 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 36

set, bag, ordered, and sequence We need a special annotation to say that the same (University/Student) pair can have multiple Enrolment links {bag} 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 37

set, bag, ordered, and sequence Consider a OS s representation of a display screen. It has a set of windows, but furthermore the set is ordered. Use the ordered annotation for ordered sets {ordered} 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 38

set, bag, ordered, and sequence Now consider a Stack of StackItems. The diagram {bag} correctly shows that the same StackItem object may appear on the same stack more than once. But we may want to further indicate that the items on each stack are ordered {sequence} 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 39

set, bag, ordered, and sequence Unfortunately the version of Rose we currently have does not support these annotations. As a work-around, use UML notes. 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 40

Qualified Associations An association may require other information. For example, given a StudentDataBase, one can find an associated Student given a student number Could be implemented by an array or a some kind of map structure (search tree or hash table). 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 41

n-ary Associations Normally associations are binary, but we can have n-ary associations for n > 2. Multiplicities are given assuming all other objects are fixed. Example: In a genogram application we might have 2003 T. S. Norvell Engineering 5895 Memorial University Slide set 2. Slide 42