Layered and hexagonal architecture

Layered architecture and its dependency rule, then hexagonal architecture: domain at the centre, ports, primary and secondary adapters, and dependency inversion.

  • 22 cards
  • 3 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link

A few cards from the deck

  • Layered architecture: what is it?

    Show the answer

    An organisation of software into stacked strata, presentation, application, domain, persistence, where each stratum relies only on the ones below.

    A stratum can be replaced without touching the ones above: changing the database should not force rewriting the screens.

  • In this domain class, which line breaks the hexagonal architecture?

    ```java
    package fr.iut.commande.domaine;

    import java.sql.Connection;
    import java.util.List;

    public class Commande {
    private final List<Ligne> lignes;

    public void enregistrer(Connection connexion) {
    connexion.prepareStatement("INSERT INTO commande VALUES (?)");
    }
    }
    `

    • import java.sql.Connection;
    • package fr.iut.commande.domaine;
    • private final List<Ligne> lignes;
    • import java.util.List;
    Show the answer

    import java.sql.Connection;

    A standard-library list ties the domain to no technology, but java.sql.Connection is a technical type (JDBC): the domain now depends on the database. It should declare a port, for example DepotCommande, that persistence will implement.

  • In a classic layered architecture, dependencies always go …: presentation calls application, which calls the domain.

    Show the answer

    In a classic layered architecture, dependencies always go downwards: presentation calls application, which calls the domain.

    In the strict variant, a layer talks only to the layer directly below; in the relaxed variant, it may also skip a layer.

  • Dependency rule: what is it?

    Show the answer

    The constraint that a layer of a program may depend only on the ones beneath it, never on the ones above.

    If the domain imported a screen class, it could no longer be tested or reused without dragging the interface along: a single upward dependency is enough to ruin the split.

  • In a hexagonal architecture, which way does the dependency go between DepotCommandeSql and DepotCommande (the domain's interface)?

    • DepotCommande depends on DepotCommandeSql
    • DepotCommandeSql depends on DepotCommande
    • The two depend on each other
    • No dependency: an interface has no link with its implementations
    Show the answer

    DepotCommandeSql depends on DepotCommande

    A class that implements an interface depends on that interface. Since the interface lives in the domain, the technical dependency points towards the domain, not the other way round.