ITTDublin2016

1. About me and this course

1.1. Who am I ?

  • Professor logo iut dublin trip

  • Head of the MACAO [1] team of the CNRS/IRIT Lab logo irit

  • Teaching Undergraduate (IUT), M.Sc. (Master), Doctorate:

1.2. Topics

This course will consist in :

1.3. Time schedule

Monday
  • 9-11am room 212

  • 13-15h room 215

TuesDAY
  • 9-11am room 212

  • 13-15h room 221

2. Concepts and definitions

2.1. Before starting

A class as a "record"
public class Student {
	String name;
}
A universal, graphical representation of a class
Figure 1. A universal, graphical representation of a class

2.2. We need to agree on a notation

  • UML™

  • ⇒ Independant from coding language (Java, PHP, …​)

2.3. Data vs Information

A data (e.g., 37.2) is raw, it has no meaning until it becomes an information (e.g., "temperature in Celcius").

A variable stores a data that represents an information.

2.4. Objects

JSON example
{
  "jmb": {
    "location": "Toulouse",
    "name": "Jean-Michel Bruel",
    "country": "France"
  },
  "am": {
    "location": "Dublin",
    "name": "Andrew Donnellan",
    "country": "Ireland"
  }
}

2.5. Properties

In the previous example, each object has the same properties:

  • location

  • name

  • country

2.6. Class

A class as abstraction of Objects
Figure 2. A class as abstraction of Objects

A class is not a set of objects (hence no prurial on its name)!

2.7. Attributes

In the previous example, for the People class, we have defined some attributes:

  • location

  • name

  • country

So far you should wonder why I used 2 different words for the same concepts: properties and attributes, but we’ll see why in a minute…​

An attribute is a characteristic of an objet (person’s name, color of a car, average grade of a stydent…​).

Each object is characterized by the set of values of its attributes.

2.8. Special kind of attribute : Identifiers

An identifier (or "Id") is an attribute that is unique for each object (e.g., social seciruty number).

We will make those attributes explicitely identifiers, by preceeding their name with id (e.g., idStudent).

2.9. Conventions

You might have noticed that I used the same conventions for naming things (same as Java):

  • 1st letter of a class, always in Capital (e.g., Student, People)

  • 1st letter of a properties, never in Capital (e.g., name,dateOfBirth)

  • no plurial on class name

2.10. Back to object notation (in UML)

  • In classical programming languages (such as C), we talk about type and variable.

  • In object oriented programming (and hence in UML) we will talk about class and object (or also instance).

UML representation of an object
Figure 3. UML representation of an object

2.11. Associations

2.11.1. Definition

Through association we are going to model links between objects.

Let’s start with an example :

Some objects we would like to link
Figure 4. Some objects we would like to link
Some objects now linked
Figure 5. Some objects now linked
Advantage
  • Now we know they belong to the same team

  • Now we know the content of the team

Problem
  • We cannot do that for all the objects!!

Links at the class level => associations
Figure 6. Links at the class level ⇒ associations

2.11.2. Dimension of an association

An association between two class is a binary association.

We will see others (such as ternary associations) later.
Example of binary association

prod fourn

2.11.3. Name of an association

An association has a name (often a verb). It is not mandatory, but sometimes usefull to understand the links between objects.

Links at the class level => associations
Figure 7. Links at the class level ⇒ associations

2.11.4. Multiplicity

It is important to visualize the number of objects on one side, in association with the objects on the other side. Most of the time this number is not fixed, but is a range denoted M..N.

On M..N, M must always be lower or equal to N (e.g., 3..10).

Links at the class level => associations
Figure 8. Links at the class level ⇒ associations

Usual situations:

  • ⇒ multiple optional (meaning 0..).

  • 1..* ⇒ multiple mandatory

  • 1 ⇒ mandatory (meaning 1..1)

3. Advanced concepts

  • How association are "stored" ?

  • Navigability

  • Class-Association

  • Ternary (and more) association

  • Ownership

  • Link with databases

3.1. How association are "stored" ?

Let’s have a look at some java code…​

3.2. Navigability

What are the differences between those two associations:

assoc6
assoc7

Question: write the corresponding Java classes.

3.3. Class association

Some associations have properties!

Example: the price at which a product is proposed by a given provider.

assoc8

3.4. Ternary (and more) association

3.5. Ownership

In lots of situations, we want an extra link between objects: a life-time dependency. One object (the whole) possess the other (the part). This is called an composition and is represented with a dedicated notation in UML™:

assoc9
  • The "black diamond" is on the whole side

  • The multiplicity on the whole side is always 1

  • It is often the case that this kind of association is a one-way association (from the whole to the parts)

  • Importance of the "Id" -

4. Practice & exercices

4.1. Easy class diagrams

4.1.1. Identify concepts

In the following class diagram, find those elements :

  1. Class

  2. Class names

  3. attributes

  4. associations

  5. multiplicities

dc1

4.1.2. Class diagrams

Model the following situations through class diagrams:

  1. Laptops

    • A laptop has a keyboard

    • A keyboard has a type ("azerty" or "querty")

    • A keyboard has some keys

    • A laptop can have an owner, himself having a first and last name

    • A laptop has a price (when bought) and a value (actual)

  2. Model the IP datagrams class and find some associations with other classes. Make sure to put names, multiplicities.

  3. Pick up your favorite domain and model the data as classes

4.2. Second level class diagrams

Model the following situations through class diagrams:

  • Exams

    • Students have a number, a name, a firstname, a date of birth. They follow some courses (title, code).

    • The exams concern a given course. Each exam has a date and coef.

    • For each exam a student has a grade.

    • Course are taugt by professors (name, firstname)

4.3. Other exercices

4.3.1. Reverse Engineering

Considering the following Java codes:

Accident.java
package accidents;
import java.sql.Date;
import java.sql.Time;

public class Accident
{
  private String id;
  private String description;
  private Date date;
  private Time time;
  private String other_details;

  private Employee employee;
  private AccidentType accidentType;
  private SeriousnessLevel seriousnessLevel;

  public Accident(String aId, String aDescription, Date aDate, Time aTime, String aOther_details, Employee aEmployee, AccidentType aAccidentType, SeriousnessLevel aSeriousnessLevel)
  { ... }
  // gettes and setters
  ...
  public Employee getEmployee(){ ... }
  public AccidentType getAccidentType(){ ... }
  public SeriousnessLevel getSeriousnessLevel(){ ... }
  public boolean setEmployee(Employee aEmployee){ ... }
  public boolean setAccidentType(AccidentType aNewAccidentType){ ... }
  public boolean setSeriousnessLevel(SeriousnessLevel aNewSeriousnessLevel){ ... }
}
AccidentType.java
package accidents;
public class AccidentType
{
  private String code;
  private String description;

  public AccidentType(String aCode, String aDescription){ ... }
  ...
}
Employee.java
package accidents;
public class Employee
{
  private String id;
  private String department;
  private String name;
  private String supervisor;
  private String other_employee_details;

  private List<Accident> accidents;

  public Employee(String aId, String aDepartment, String aName, ...){ ... }
  public Accident getAccident(int index){ ... }
  public List<Accident> getAccidents(){ ... }
  public int numberOfAccidents(){ ... }
  public boolean hasAccidents(){ ... }
  public int indexOfAccident(Accident aAccident){ ... }
  public static int minimumNumberOfAccidents(){return 0;}
  public Accident addAccident(String aId, String aDescription, Date aDate, ...){ ... }
  public boolean addAccident(Accident aAccident){ ... }
  public boolean removeAccident(Accident aAccident){ ... }
}
SeriousnessLevel.java
package accidents;

public class SeriousnessLevel
{
  private String code;
  private String description;

  public SeriousnessLevel(String aCode, String aDescription){ ... }
}

Make the corresponding class diagram.

4.3.2. Air France

When not in strike, the crue of an AF flight is composed of a pilote, a copilote and several personnels, called PNC. Each of these persons are identified by his/her name and function. A crue on a plane is different for each flight.

Each crue member has to be acredited on two categories of planes (e.g.,) Richard is operational on Airbus A320 & Boeing 747). Each plane category requires a certain number of PNC (a minimum & a maximum).

Here is an example of flight planning:

airfranceplanning

Realize the class diagram that represents those data.

5. Tools

plantUML

You like to draw? You prefer programming?

Papyrus

Wanna try professional environment?

6. Modeling is not (just) drawing

  • With a modeling tool ⇒ respect of the notation

  • Global vision and links between elements

About…​

Material by J.-M. Bruel via Asciidoctor (v.1.5.5) from 'Dan Allen'. 'Licence Creative Commons'. licence Creative Commons Paternity. Licence Creative Commons


1. Models, Aspects, Components, Architecture & Objects