Umple Mini-Course Part 1: The Basics

Slides:



Advertisements
Similar presentations
 2005 Pearson Education, Inc. All rights reserved Introduction.
Advertisements

CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chapter 6: Using Design Patterns
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Chapter 13: Object-Oriented Programming
Creating Web Page Forms
Exploring a Model-Oriented and Executable Syntax for UML Attributes SERA 2013SERA 2013 (August 7, 2013 in Prague, Czech Republic) Omar Badreddin, Andrew.
The Umple Model-Oriented Programming Technology: Easy-to-Use Open-Source Code Generation Code Generation 2013, Cambridge UK Timothy C. Lethbridge, University.
A First Program Using C#
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
1 Using Classes Object-Oriented Programming Using C++ Second Edition 5.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
CSCI-383 Object-Oriented Programming & Design Lecture 9.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Improving Code Generation for Associations: Enforcing Multiplicity Constraints and Ensuring Referential Integrity SERA 2013SERA 2013 (August 7, 2013 in.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
 All calls to method toString and earnings are resolved at execution time, based on the type of the object to which currentEmployee refers.  Known as.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
CSCI-383 Object-Oriented Programming & Design Lecture 10.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Separation Of Concerns: Mixins + Variability Models + Aspects in Umple CSER – June 2013 – Montreal Timothy C. Lethbridge, University of Ottawa
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Object-Oriented Software Engineering Practical Software Development using UML and Java Modelling with Classes.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
1 More About Derived Classes and Inheritance Chapter 9.
Development Environment
The need for Programming Languages
Programming Logic and Design Seventh Edition
Working in the Forms Developer Environment
Unified Modeling Language
3 Introduction to Classes and Objects.
Introduction to Classes and Objects
Chapter 16 UML Class Diagrams.
Chapter 11 Object-Oriented Design
Testing and Debugging.
Review: Two Programming Paradigms
Chapter 3: Using Methods, Classes, and Objects
Introduction to C Topics Compilation Using the gcc Compiler
Intro to PHP & Variables
Chapter 6: Using Design Patterns
CS 174: Server-Side Web Programming February 12 Class Meeting
Object Oriented Analysis and Design
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 10 Thinking in Objects
Chapter 9 Object-Oriented Programming: Inheritance
Module 8 – Database Design Using the E-R Model
Lecture 22 Inheritance Richard Gesick.
Packages and Interfaces
Week 6 Object-Oriented Programming (2): Polymorphism
Object-Oriented Programming Using C++ Second Edition
Models 2015 M. Garzón, A. Forward, and T. Lethbridge
Part 2: Building On the Basics
Teaching Effective UML Modeling by Combining it with Programming
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Introducing JavaScript
Review of Previous Lesson
Chapter 6b: Database Design Using the E-R Model
Presentation transcript:

Umple Mini-Course Part 1: The Basics Timothy C. Lethbridge, I.S.P, P.Eng. University of Ottawa, Canada tcl@eecs.uottawa.ca http://www.umple.org

Umple: Simple, Ample, UML Programming Language Open source textual modeling tool and code generator Adds modeling to Java,. C++, PHP Key features Referential integrity on associations Constraints Infinitely nested state machines, with concurrency Patterns, mixins, traits, and more Tools Command line compiler Web-based tool (UmpleOnline) for demos and education Eclipse plugin Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics Websites Entry-point: http://umple.org Github: https://github.com/umple/umple These slides (more to be added for final day): http://www.site.uottawa.ca/~tcl/tmp/UmpleMiniCourse/ Or http://bit.ly/2r8eHEv Umple Mini-Course Part 1: The Basics

The User Manual and Hello World Go to http://helloworld.umple.org Look at the first example Observe: just a plain method Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics What Are we Going to Learn About in This Mini-Course? What Will You Be Able To Do? Modeling using class diagrams Attributes, Associations, Methods, Patterns, Constraints Review of translating requirements into a model Practice with a variety of examples Modeling using state diagrams States, Events, Transitions, Guards, Nesting, Actions, Activities Concurrency Separation of Concerns in Models Mixins, Traits, Aspects Analysis of Models Building complete systems Umple Mini-Course Part 1: The Basics

What Technology Will You Need (1)? For homework, and ideally for in-class work A computer (laptop) with Java 8 JDK and Umple Mac and Linux are the easiest platforms, but Windows should work If you don’t have a computer in class, then you will need a smartphone to respond to some test questions. Umple Mini-Course Part 1: The Basics

What Technology Will You Need (2)? We will mostly be using Umpleonline in a web browser: http://try.umple.org Umple on the command line: http://dl.umple.org Java 8 JDK on the command line: http://bit.ly/1lO1FSV Options Umple in Eclipse https://github.com/umple/umple/wiki/InstallEclipsePlugin cmake and gcc for compiling C++ code If you are adventurous, you can gain some speed by setting up a local UmpleOnline server https://github.com/umple/umple/wiki/SettingUpLocalUmpleOnlineWebServer Umple Mini-Course Part 1: The Basics

Tell Me About Yourselves? Year of Study? Experience with UML? What modeling tools have you used? Experience with generating code? Experience with Java? C++? Formal Methods? Go to this survey: https://www.surveymonkey.com/r/TellMe-IsraelUmple Umple Mini-Course Part 1: The Basics

Exercise: Compiling and Changing a Model Look at the example at the bottom of http://helloworld.umple.org (also on next slide) Observe: attribute, association, class hierarchy, mixin Click on Load the above code into UmpleOnline Observe and modify the diagram Add an attribute Make a multiplicity error, then undo Generate code and take a look Download, compile and run if you want Umple Mini-Course Part 1: The Basics

Hello World Example 2 in the User Manual Umple Mini-Course Part 1: The Basics

Hello World Example 2 in UmpleOnline Umple Mini-Course Part 1: The Basics

Demo of Compiling on the Command Line To compile on the command line you will need Java 8 Download Umple from http://dl.umple.org Basic compilation java -jar umple.jar model.ump java -jar umple.jar --help To generate and compile the java to a final system java –jar umple.jar model.ump -c - Umple Mini-Course Part 1: The Basics

Exploration of UmpleOnline Explore class diagram examples Explore options View – hide and showing text, diagram Control-t (text), control-d (diagram) as shortcuts View – hide and showing methods, attributes Generate different default diagram types Control-g (Graphviz), control-s (state), control-e Generate code and look at the results In Umple you never should modify generated code, but it is designed to be readable for educational purposes Umple Mini-Course Part 1: The Basics

Quick Walkthrough of the User Manual http://manual.umple.org Note in particular Key sections: attributes, associations, state machines Grammar Generated API Errors and warnings Editing pages in github Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics Attributes ”Instance variables” Part of the state of an object Simple data that will always be present in each instance Specified like a Java or C++ field or member variable But, intended to be more abstract! Always private by default Should only be accessed get, set methods Can be stereotyped (upcoming slides) Can be constrained (discussed later) Umple Mini-Course Part 1: The Basics

Umple Builtin Datatypes String // (default if none specified) Integer Float Double Boolean Time Date The above will generate appropriate code in Java, C++ etc. e.g. Integer becomes int Other (native) types can be used but without guaranteed correctness Umple Mini-Course Part 1: The Basics

Some Stereotypes Used on Attributes By default, each attribute adds an argument to the generated constructor To prevent this, use one of these autounique x; // sets attribute to 1, 2, 3 … lazy b; // sets it to null, 0, “” depending on type a = "init value"; defaulted s = "def"; // resettable to the default internal i; // doesn’t generate any get/set either More more details: http://attributes.umple.org Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics Immutability Useful for objects where you want to guarantee no possible change once created e.g. a geometric point Generate a constructor argument and get method but no set method  immutable String str;  No constructor argument, but allows setting just once. lazy immutable z;  Umple Mini-Course Part 1: The Basics

Generalization in Umple Umple uses the isA keyword to indicate generalization class Shape { colour; } class Rectangle { isA Shape; Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics Interfaces Declare signatures of a group of methods that must be implemented by various classes Also declared using the keyword isA Essentially the same concept as in Java Let’s explore examples in the user manual … Umple Mini-Course Part 1: The Basics

User-Written Methods in Umple Methods can be added to any Umple code. Umple parses the signature only; the rest is passed to the generated code. You can specify different bodies in different languages We will look at examples in the user manual … Umple Mini-Course Part 2: Building on The Basics

Umple Mini-Course Part 1: The Basics Time for a Test Go to the following URL for a little test https://www.surveymonkey.com/r/Test1-UmpleIsrael Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics Basic Associations Manage dynamic links among instances of classes Multiplicity symbols indicate how many instances Umple Mini-Course Part 1: The Basics

Many-to-One Associations A company has many employees, An employee can only work for one company. This company will not store data about the moonlighting activities of employees! A company can have zero employees E.g. a ‘shell’ company It is not possible to be an employee unless you work for a company Employee 1 * Company Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics Associations in Umple class Employee { id; firstName; lastName; } class Company { name; 1 -- * Employee; Umple Mini-Course Part 1: The Basics

Referential Integrity When an instance on one side of the association changes The linked instances on the other side know … And vice-versa This is standard in Umple associations, which are bidirectional Umple Mini-Course Part 1: The Basics

Role Names (optional, in most cases) Allow you to better label either end of an association class Person{ id; firstName; lastName; } class Company { name; 1 employer -- * Person employee; Umple Mini-Course Part 1: The Basics

Many-to-Many Associations An assistant can work for many managers A manager can have many assistants Assistants can work in pools working for several managers Managers can have a group of assistants Some managers might have zero assistants. Is it possible for an assistant to have, perhaps temporarily, zero managers? * supervisor 1..* Assistant Manager Open in Umple Umple Mini-Course Part 1: The Basics

One-to-One Associations (Use Cautiously) For each company, there is exactly one board of directors A board is the board of only one company A company must always have a board A board must always be of some company 1 Open in Umple Umple Mini-Course Part 1: The Basics

Typical Erroneous Use of One-to-One Avoid this do this Umple Mini-Course Part 1: The Basics

Unidirectional Associations Associations are by default bi-directional It is possible to limit the direction of an association by adding an arrow at one end In the following unidirectional association A Day knows about its notes, but a Note does not know which Day is belongs to Note remains ‘uncoupled’ and can be used in other contexts class Day { * -> 1 Note; } class Note {} Open in Umple Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics Association Classes Sometimes, an attribute that concerns two associated classes cannot be placed in either of the classes The following are nearly equivalent The only difference: in the association class there can be only a single registration of a given Student in a CourseSection Open in Umple and extended example Umple Mini-Course Part 1: The Basics

Association Classes (cont.) Umple code class Student {} class CourseSection {} associationClass Registration { * Student; * CourseSection; } Open in UmpleOnline, and then generate code Umple Mini-Course Part 1: The Basics

Reflexive Associations An association that connects a class to itself class Course { * self isMutuallyExclusiveWith; // Symmetric } association { * Course successor -- * Course prerequisite; Open in Umple Umple Mini-Course Part 1: The Basics

Modeling Hierarchies of Instances Either: Use a reflexive 1 -- * association Or use the composite pattern: class Employee { name; } class Manager { isA Employee; 0..1 -- * Employee subordinate; Class OrdinaryEmployee { Umple Mini-Course Part 1: The Basics

In-Class Modeling Exercises Build a class diagram for the following. If you think there are key requirements missing, then add them. 1. A building can have many floors and several elevators. Each elevator serves a set of floors 2. A football (soccer) team has players. Each player plays a position. The team plays some games against other teams during each season. The system needs to record who scored goals, and the score of each game. Umple Mini-Course Part 1: The Basics

Homework after First Class Model the following in Umple: A bus company has a set of busses of three different types. Each type has a different capacity. The company runs busses on various routes. Each route stops at a set of routes. Some routes run every n minutes from a start time to a stop time each day, other than holidays. Other routes run at specific times. Write some Umple code (Java methods) to create some instances of your each of your classes and then print out the results. Umple Mini-Course Part 1: The Basics

How to Submit your Bus System 1. Write the Umple code and compile it 2. Run the system and after it works save the output as a text file 3. Generate a graphviz class diagram and save as a file too 4. Create a zip file with: Umple code + diagram + text file Submit the zip file to the following link: http://bit.ly/2r0ynvq or https://www.dropbox.com/request/HcOJzhfuZmXmhDuzmAMx Umple Mini-Course Part 1: The Basics

Avoiding Unnecessary Generalizations Skip the next 6 slides if time is short: Students read at home Avoiding Unnecessary Generalizations Inappropriate hierarchy of Classes What should the model be? Umple Mini-Course Part 1: The Basics

Avoiding Unnecessary Generalizations (cont) Open in Umple Improved class diagram, with its corresponding instance diagram Umple Mini-Course Part 1: The Basics

Associations Versus Generalizations Associations describe the relationships that will exist between instances at run time. When you show an instance diagram generated from a class diagram, there will be an instance of both classes joined by an association Generalizations describe relationships between classes in class diagrams. They do not appear in instance diagrams at all. An instance of any class should also be considered to be an instance of each of that class’s superclasses Umple Mini-Course Part 1: The Basics

An Important Association Pattern: Abstraction-Occurrence Chapter 6: Using design patterns © Lethbridge/Laganière 2012

Antipatterns to Abstraction Occurrence Don’t do these!! Chapter 6: Using design patterns © Lethbridge/Laganière 2012

Square Abstraction-Occurrence Try modeling these in Umple Chapter 6: Using design patterns © Lethbridge/Laganière 2012

More Details on Associations We will revisit associations in Mini-Course 2 But explore http://associations.umple.org for more detail right now Umple Mini-Course Part 1: The Basics

Time for Another Short Test Go to the following link https://www.surveymonkey.com/r/Test2-UmpleIsrael Umple Mini-Course Part 1: The Basics

Wrapup on Part 1: Umple Philosophy 1-4 P1. Modeling is programming and vice versa P2. An Umple programmer should never need to edit generated code to accomplish any task. P3. The Umple compiler can accept and generate code that uses nothing but UML abstractions. The above is the inverse of the following P4. A program without Umple features can be compiled by an Umple compiler. e.g. input Java results in the same as output Umple Mini-Course Part 1: The Basics

Umple Mini-Course Part 1: The Basics Umple Philosophy 5-8 P5. A programmer can incrementally add Umple features to an existing program Umplification P6. Umple extends the base language in a minimally invasive and safe way. P7. Umple features can be created and viewed diagrammatically or textually P8. Umple goes beyond UML Umple Mini-Course Part 1: The Basics

The Course Continues in Part 2 We will look at: Multi-valued and derived attributes Keys Enumerations Patterns: Singleton and delegation Constraints Basic state machines Umple Mini-Course Part 1: The Basics