C4 and UML Notations

Agenda

  • Object orientation

  • UML

  • C4

Object-Orientation

Object-orientation rules the software world.

The programming languages C++, Java, C#, Python, Typescript, Ruby, Switft, Rust, or Delphi includes object-orientation features.

What is an Object?

An object has three capabilities:

  • Identity is unique in the system

  • State is composed of attributes

  • Behavior is defined with methods

What is a Class?

  • A class is a template for a set objects.
    It defines the available attributes and their type.
    It declares the behavior of the objects.

  • An interface is a behavior template.

  • An abstract class defines state and behavor. It cannot have instances.

  • Primitive types have no identity.

Advanced Approaches

  • Templates are classes with generic types and constants.

  • Mixins are a kind of interfaces or abstract classes. They codify an orthogonal abstraction.

Why Do You Model?

  • Designing is an activity

  • A design represents an artifact representing some findings. This artifact is obsolete when you continue designing.

  • The model codifies your findings and partially describes the implementation.

Software Design Principles

  • Modularity

  • Cohesion

  • Separation of concerns

  • Information hiding

  • Abstraction

Idioms

The design is constrained by

  • The technology stack

  • The team capabilities

  • The non-functional requirements

architecture constraints

Functional Approaches

  • Functions are first-class citizens

  • Functions can be variables, parameters, and return values

Design patterns such as the visitor, strategy or factory pattern are easily implemented with functions.

UML and C4

  • UML is the modeling approach for object-oriented systems originating in the eighties

  • C4 Model is a simplification to the exploding complexity of UML 2.5

  • Choose the tools empowering you to create the optimal design for your product

UML Diagram Types

uml diagram types

Class Diagram

uml-class-diagram

Relations

  • Association shows a dependency between two class

  • Inheritance extends a class

  • Realization implements an interface

  • Dependency uses a class

  • Aggregation instance has other objects

  • Composition lifecycle is the same

Properties and Methods

  • Properties define the state of an object

  • Methods define the behavior of an object

A big chunk of the source code is the implementation of methods.

Visibility and Specifiers

  • private, package-private, protected, public

  • static

  • abstract

  • derived

  • {readonly}

Advanced Topics

  • Property default value, cardinality, ordered

  • Association roles

  • Constraints {…​}

  • Stereotypes

  • Tags

  • Notes

  • Navigability

Thoughts

  • Class diagrams visualize the object-oriented structure of your source code

  • Their value is the abstraction to highlight key concepts

  • Details are available in the source code

Component Diagram

  • defines the structure of the architecture in components

  • distribution structure such as libraries and executables

  • source code structure

Component Diagram

uml-component-diagram

Thoughts

  • Provide an overview to highlight your component structure

  • Beware that modern programming languages support a textual representation of this structure

Package Diagram

  • structure of source code in package and modules. You can show your layered architecture with a package diagram.

Deployment Diagram

  • physical distribution of artifacts on nodes, cores, and processes

  • Communication between nodes

Object Diagram

  • A set of concrete instances of classes and their relations

  • Sequence diagram

  • Communication diagram

Sequence Diagram

uml-sequence-diagram

Advanced Concepts

  • Activation frames

  • Synchronous and asynchronous calls

  • Return values

  • Interaction Frames

  • Creation and deletion of instances

State Machine Diagram

Rules

  • A state machine is inside a class

  • Events are asynchronous messages

  • Avoid activities and concurrent states

  • Timeout requires a global time provider

State Machine Diagram

uml-state-diagram

Requirements Aspects

  • Use case diagram

  • Activity diagram

Use Case Diagram

uml-use-case-diagram

Activity Diagram

uml-activity-diagram

Embedded Considerations

  • Heap and Dynamic Object Allocations

  • Threads

  • Interrupt Routines

UML and C4

The C4 Model is:

  1. A set of hierarchical abstractions: software systems context, containers, components, and code

  2. A set of hierarchical diagrams: system context, containers, components, and code

  3. Notation and tooling independent

System Context Diagram

c4 system context

Container Diagram

c4 containers

Component Diagram

c4 components

Code Diagram

c4 class diagram

Advanced Diagrams

  • System Landscape Diagram

  • Dynamic Diagram

  • Deployment Diagram

Thoughts

Although the example diagrams above are created using a boxes and lines notation, the core diagrams can be illustrated using UML.