Presentation on theme: "UML (cont.) “The Unified Modeling Language User Guide” by G. Booch, J. Rumbaugh and I. Jacobson ● Classes ● Relationships ● Class diagrams ● Examples."— Presentation transcript:
UML (cont.) “The Unified Modeling Language User Guide” by G. Booch, J. Rumbaugh and I. Jacobson ● Classes ● Relationships ● Class diagrams ● Examples
Classes ● Modelling a system involves identifying the things that are important to your view of the system: the vocabulary of the system. ● A class is a description of a set of objects that share the same attributes, operations, relationships and semantics.
Classes ● Names ● Abstract classes (names are written in italics). ● Attributes ● An attribute is a named property of a class, shared by all objects of that class. ● A attribute may have associated a type or a default initial value.
Classes ● Operations ● An operation is something that can be done to any object of that class. Represents some behaviour of its enclosing class. ● You can specify the signature of an operation, covering the name and type of all parameters, and a return type (in the case of functions).
Relationships ● When you model a system, not only must you identify the things that form the vocabulary of your system, but must also model how these things stand in relation to one another. ● A relationship is a connection among things. ● Three kinds of relationships that are important: ● Dependency ● Generalization ● Association
Relationships ● Dependencies: ● Dependencies are using relationships among classes. ● A dependency states that a change in specification of one thing may affect another thing that uses it, but not necessarily the reverse. The latter depends on the former. ● Use dependencies when you want to show one thing using another (e.g. one class uses another class as an argument in the signature of an operation).
Relationships ● Generalization ● A generalization is a relationship between a general thing (the superclass or parent) and a more specific kind of thing (the subclass or child). ● Generalization is an “is-a-kind-of” relationship. ● Generalization means that objects of the child class may be used anywhere the parent class may appear, but not the reverse. ● A child class inherits the attributes and the operations of its parents. Often the child has adittional attributes and/or operations.
Relationships ● Generalization (cont.) ● An operation of a child that has the same signature as an operation of a parent, overrides the operation of the parent. ● A class may have zero, one or more parents. A class that has no parents and one or more children is called a root class. A class that has no children is called a leaf class. ● A class that has exactly one parent is said to use single inheritance. A class with more than one parent is said to use multiple inheritance.
Relationships ● Association ● An association is a structural relationship that specifies that objects of one thing are connected to objects of another. ● Name: An association can have a name to describe the nature of the relationship. Usually you can give a direction to the name. ● Role: When a class participates in an association, it has a specific role that it plays in that relationship. You can name the role a class plays in an association.
Relationships ● Association: ● Multiplicity: In many modelling situations, it is important to state how many objects may be connected across an instance of an association. Multiplicity may be: exactly one (1), zero or one (0..1), many (0..*), or one or more (1..*). ● Aggregation: In a plain association between two classes, both classes are conceptually at the same level. When you want to model a “whole/part” relationship, in which one class represents a larger thing (the wole), which consists of smaller things (the parts).