Table of Contents

Basics of Unified Modelling Language

Structural Diagrams

Structural diagrams can be used to model structure of the software. The most important aspects of the class diagrams are the Class diagrams including inheritance and aggregations.


Class diagram

Fooint privateMembervoid publicMethod()void protectedMethod()

Same as C++ code:

class Foo {
public:
    void publicMethod();
protected:
    void protectedMethod();
private:
    int privateMember;
};

Inheritance

AnimalBirdMammalBearPenguinChickenRaven

Same as C++ code:

class Animal {
};

class Bird : public Animal {
};

class Mammal : public Animal {
};

class Penguin : public Bird {
};

class Chicken : public Bird {
};

class Raven : public Bird {
};

class Bear : public Mammal {
};

Association

An association represents a family of links. Typically associations is used to describe relationship between classes. A binary association (with two ends) is normally represented as a line. An association can link any number of classes. An association with three links is called a ternary association. An association can be named, and the ends of an association can be adorned with role names, ownership indicators, multiplicity, visibility, and other properties.

An example on association, describing situation where Foo-class uses Bar class:

FooBar«uses»

Same as C++ code (in this case Foo uses Bar at method call):

Foo:someMethod(Bar* theBar) {
    theBar->doSomething();
}

Aggregation

Aggregation is a variant of the “has a” association relationship; aggregation is more specific than association. It is an association that represents a part-whole or part-of relationship.

An example on association, describing situation where Car has four tires. Note that wheels are independent on car, so if car is deleted, tires Still exist:

CarWheel4

Same as C++ code:

class Wheel {
};

class Car {
    Wheel* m_wheels[4];
};

Composition

An example on association, describing situation where Car has four tires. Note that wheels are dependent on car, so if car is deleted, tires are deleted too:

CarWheel4

Same as C++ code:

class Wheel {
};

class Car {
    Wheel m_wheels[4];
};

Behavioral diagrams

State Chart diagrams.

Locked Violation Unlocked coin / unlock()pass / lock()pass / alarm()reset / lock()coin/ thankYou()

C++ code implementation:

enum EventType { PASS, COIN, RESET };
enum State { LOCKED, UNLOCKED, VIOLATION }
State currentState = LOCKED;
void event(EventType ev) {
    switch(currentState) {
    case LOCKED:
        switch(ev) {
        case PASS:
            alarm();
            currentState = VIOLATION;
            break;
        case COIN:
            unlock();
            currentState = UNLOCKED;
            break;
        }
        break;
    case UNLOCKED:
        switch(ev) {
        case PASS:
            lock();
            currentState = LOCKED;            
            break;
        case COIN:
            thankYou();
            break;
        }
        break;
    case VIOLATION:
        switch(ev) {
        case RESET :
            lock();
            currentState = LOCKED;
            break;
        }
        break;
}

Sequence diagrams

UserUserAABBCCDoWork«createRequest»DoWorkWorkDoneRequestCreatedDone