1. About me and this course
2. Concepts and definitions
2.1. Before starting
public class Student {
String name;
}
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
{
"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 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 |
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
andvariable
. -
In object oriented programming (and hence in UML) we will talk about
class
andobject
(or alsoinstance
).
2.11. Associations
2.11.1. Definition
Through association we are going to model links between objects.
Let’s start with an example :
- 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!!
-
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. |
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.
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 |
Usual situations:
-
⇒ multiple optional (meaning
0..
). -
1..*
⇒ multiple mandatory -
1
⇒ mandatory (meaning1..1
)
3. Advanced concepts
-
How association are "stored" ?
-
Navigability
-
Class-Association
-
Ternary (and more) association
-
Ownership
-
Link with databases
3.2. Navigability
What are the differences between those two associations:
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.
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™:
|
3.6. Link with databases
-
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 :
-
Class
-
Class names
-
attributes
-
associations
-
multiplicities
4.1.2. Class diagrams
Model the following situations through class diagrams:
-
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)
-
-
Model the IP datagrams class and find some associations with other classes. Make sure to put names, multiplicities.
-
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:
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){ ... }
}
package accidents;
public class AccidentType
{
private String code;
private String description;
public AccidentType(String aCode, String aDescription){ ... }
...
}
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){ ... }
}
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:
Realize the class diagram that represents those data.
5. Tools
6. Modeling is not (just) drawing
-
With a modeling tool ⇒ respect of the notation
-
Global vision and links between elements