Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Domain-Driven Design – Unterlagen Zusatzprogramm

Domain-Driven Design – Unterlagen Zusatzprogramm

WPS – Workplace Solutions

January 01, 2020
Tweet

More Decks by WPS – Workplace Solutions

Other Decks in Programming

Transcript

  1. www.wps.de WPS – Workplace Solutions INHALT § Pflichtprogramm § Unter

    https://speakerdeck.com/wps § Zusatzprogramm § Die Building Blocks implementieren § Event Sourcing und CQRS § Microservices § Entwurfsmetaphern aus WAM § Ideen kommunizieren
  2. IMPLEMENTIEREN DER BUILDING BLOCKS WPS – Workplace Solutions #dddkonkret www.wps.de

    IMPLEMENTIEREN DER BUILDING BLOCKS Domain-Driven Design konkret 1 17.12.20 //// Seite 2 WPS – Workplace Solutions ÜBERSICHT § Entities Implementieren § Beispiel-Entity § Vertragsmodell (Design by contract) § Beispiel-Value-Object § Identität von Entities DOMÄNE DOMÄNE 2
  3. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 3 WPS –

    Workplace Solutions 3 17.12.20 //// Seite 4 WPS – Workplace Solutions EIN BANKKONTO – ERSTER ENTWURF public class Account { } 4
  4. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 5 WPS –

    Workplace Solutions EIN BANKKONTO – ERSTER ENTWURF import org.jmolecules.ddd.annotation.Entity; @Entity public class Account { } 5 17.12.20 //// Seite 6 WPS – Workplace Solutions EIN BANKKONTO – ERSTER ENTWURF @Entity public class Account { private int _balance; public int getBalance() { return _balance; } public void setBalance(int balance) { _balance = balance; } } ✘ Schlecht: Der Kontostand kann auf beliebigen Wert gesetzt werden 6
  5. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 7 WPS –

    Workplace Solutions EIN BANKKONTO – ZWEITER ENTWURF @Entity public class Account { private int _balance; public int balance() { return _balance; } public void deposit(int amount) { _balance += amount; } public void withdraw(int amount) { _balance -= amount; } } Besser: Methoden mit fachlichem Verhalten und Namen 7 17.12.20 //// Seite 8 WPS – Workplace Solutions EIN BANKKONTO – DRITTER ENTWURF @Entity public class Account { private int _balance; public int balance() { return _balance; } public void deposit(int amount) { _balance += amount; } public void withdraw(int amount) { if (amount > balance()) { throw new IllegalArgumentException("Amount too big"); } _balance -= amount; } } Noch besser: Vorbedingungen können geprüft werden 8
  6. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 9 WPS –

    Workplace Solutions DESIGN BY CONTRACT Foto: Urheber Fuchsias/Bertrand Meyer/Wikipedia/CC BY-SA 4.0 9 17.12.20 //// Seite 10 WPS – Workplace Solutions EIN BANKKONTO – VERTRAGSMODELL MIT ASSERT @Entity public class Account { // ... public void withdraw(int amount) { assert amount <= balance(); _balance -= amount; } } Prüfung mit Schlüsselwort assert 10
  7. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 11 WPS –

    Workplace Solutions EIN BANKKONTO – VERTRAGSMODELL MIT VALID4J import static org.valid4j.Assertive.*; @Entity public class Account { // ... public void withdraw(int amount) { require(amount <= balance()); _balance -= amount; } } Hamcrest Matchers können verwendet werden 11 17.12.20 //// Seite 12 WPS – Workplace Solutions VERTRAGSMODELL IN C# using System.Diagnostics.Contracts; // ... Contract.Requires(/* Prädikat */); Contract.Ensures(/* Prädikat */); 12
  8. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 13 WPS –

    Workplace Solutions EIN BANKKONTO – VERTRAGSMODELL MIT CODE CONTRACTS using System.Diagnostics.Contracts; [Entity] public class Account { // ... public void Withdraw(int amount) { Contract.Requires(amount <= Balance); _balance -= amount; } } 13 17.12.20 //// Seite 15 WPS – Workplace Solutions JA, ABER… @Entity public class Account { // ... public void withdraw(int amount) { assert amount <= balance(); _balance -= amount; } } Kann ich einen Negativen Betrag abheben? In EUR oder GBP oder … ? 15
  9. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 16 WPS –

    Workplace Solutions EIN EIGENER BETRAGS-TYP public class Amount { } 16 17.12.20 //// Seite 17 WPS – Workplace Solutions EIN EIGENER BETRAGS-TYP import org.jmolecules.ddd.annotation.ValueObject; @ValueObject public class Amount { } 17
  10. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 18 WPS –

    Workplace Solutions EIN EIGENER BETRAGS-TYP @ValueObject public class Amount { private final int _amount; private final Currency _currency; } 18 17.12.20 //// Seite 19 WPS – Workplace Solutions EIN EIGENER BETRAGS-TYP @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } } 19
  11. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 20 WPS –

    Workplace Solutions EIN EIGENER BETRAGS-TYP @ValueObject public class Amount { private final int _amount; private final Currency _currency; private Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } public static Amount of(int amount, Currency currency) { return new Amount(amount, currency); } } 20 17.12.20 //// Seite 21 WPS – Workplace Solutions EIN EIGENER BETRAGS-TYP @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } @Override public boolean equals(Object other) { return _amount == ((Amount) other)._amount && _currency.equals(((Amount) other)._currency); } } 21
  12. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 22 WPS –

    Workplace Solutions EIN EIGENER BETRAGS-TYP @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } @Override public boolean equals(Object other) { return _amount == ((Amount) other)._amount && _currency.equals(((Amount) other)._currency); } // hashCode() } 22 17.12.20 //// Seite 23 WPS – Workplace Solutions EIN EIGENER BETRAGS-TYP @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } public Amount add(Amount otherAmount) { return Amount.of(_amount + otherAmount._amount, _currency); } } Der neue Typ hat richtiges fachliches Verhalten 23
  13. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 24 WPS –

    Workplace Solutions EIN EIGENER BETRAGS-TYP @ValueObject public class Amount { private final int _amount; private final Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } public Amount add(Amount otherAmount) { assert hasSameCurrency(otherAmount); return Amount.of(_amount + otherAmount._amount, _currency); } public boolean hasSameCurrency(Amount otherAmount) { return otherAmount._currency == _currency; } } … und Verträge, die vor falschen Währungen schützen 24 17.12.20 //// Seite 25 WPS – Workplace Solutions EIN EIGENER BETRAGS-TYP – IN C# using NMolecules.DDD.ValueObject; [ValueObject] public struct Amount { private readonly int _amount; private readonly Currency _currency; public Amount(int amount, Currency currency) { _amount = amount; _currency = currency; } public Amount Add(Amount otherAmount) { Contract.Requires(HasSameCurrency(otherAmount)); return Amount.Of(_amount + otherAmount._amount, _currency); } public boolean HasSameCurrency(Amount otherAmount) { return otherAmount._currency == _currency; } } 25
  14. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 26 WPS –

    Workplace Solutions EIN BANKKONTO – VIERTER ENTWURF @Entity public class Account { private Amount _balance; public Amount balance() { return _balance; } public void deposit(Amount amount) { _balance = _balance.add(amount); } public void withdraw(Amount amount) { assert amount.isLessOrEqual(balance()); _balance = _balance.subtract(amount); } } Jetzt können wir den Betrags-Typ verwenden 26 17.12.20 //// Seite 27 WPS – Workplace Solutions EIN BANKKONTO – VIERTER ENTWURF @Entity public class Account { private Amount _balance; public Amount balance() { return _balance; } public void deposit(Amount amount) { _balance = _balance.add(amount); } public void withdraw(Amount amount) { assert amount.hasSameCurrency(balance()); assert amount.isLessOrEqual(balance()); _balance = _balance.subtract(amount); } } … und neue Verträge formulieren 27
  15. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 28 WPS –

    Workplace Solutions JEDER BOUNDED CONTEXT HAT SEIN EIGENES GLOSSAR TIEFENZAHL TIEFE AN EINEM BESTIMMTEN ORT UNTER BERÜCKSICHTIGUNG VON EBBE UND FLUT TIEFENZAHL PER ECHOLOT GEMESSENE TIEFE BEI NORMALNULL MANÖVER- PLANUNG TIEFENMESSUNG 28 17.12.20 //// Seite 29 WPS – Workplace Solutions JEDER BOUNDED CONTEXT HAT SEIN EIGENE IMPLEMENTIERUNG [ValueObject] public struct Tiefenzahl { public Tiefenzahl( int tiefeBeiNormalNull, int tidenhub) { // ... } } MANÖVER- PLANUNG TIEFENMESSUNG @ValueObject public class Tiefenzahl { public Tiefenzahl( int tiefeInDezimeter, LocalDate peildatum) { // ... } } 29
  16. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 30 WPS –

    Workplace Solutions EIN BANKKONTO – EVENT SOURCED @Entity public class Account { private List<FinancialTransaction> _transactions; public Amount balance() { // _transactions aufsummieren } public void deposit(Amount amount) { _transactions.append(new Deposition(amount)); } public void withdraw(Amount amount) { assert amount.hasSameCurrency(balance()); assert amount.isLessOrEqual(balance()); _transactions.append(new Withdrawal(amount)); } } Historie statt aktuellem Zustand 30 17.12.20 //// Seite 31 WPS – Workplace Solutions EIN BANKKONTO – EVENT SOURCED @Entity public class Account { private List<Event> _events; public Amount balance() { // _events aufsummieren } public void deposit(Amount amount) { _events.append(new DepositHappened(amount)); } public void withdraw(Amount amount) { assert amount.hasSameCurrency(balance()); assert amount.isLessOrEqual(balance()); _events.append(new WithdrawalHappened(amount)); } } Abstrakter: Event-Store 31
  17. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 32 WPS –

    Workplace Solutions IDENTITÄT VON ENTITIES § In Java hat jedes Objekt eine Identität § Nämlich seine Referenz § Das ist eine technische Identität § Eine Entität hat eine fachliche Identität § Verschiedene Objekte können dieselbe Entität repräsentieren § In verschiedenen Prozessen: z.B. auf dem Client/auf dem Server § Wenn sie gespeichert und später wieder aus der Datenbank gelesen werden. § Die fachliche Identität kann dem Benutzer bekannt sein auf zwei Arten: § Explizit (z.B. IBAN) § Implizit (z.B. UUID/GUID) ? 32 17.12.20 //// Seite 33 WPS – Workplace Solutions EIN BANKKONTO – MIT FACHLICHER IDENTITÄT @Entity public class Account { // ... private final IBAN _iban; public Account(IBAN iban) { _iban = iban; } @Override public boolean equals(Object other) { return _iban.equals(((Account)other)._iban); } } Die Identität ist unveränderlich Der Typ der Identität ist typischerweise ein Value Object Die Implementation von equals() basiert auf der Identität 33
  18. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 34 WPS –

    Workplace Solutions WER ERZEUGT EINE NEUE IDENTITÄT? § Die Datenbank § Pro: Zentral § Kann manchmal “lazy” erzeugt werden § Eine systemweite Fabrik § Für dem Benutzer bekannte Formate § Oft in dem Repository, das zum passenden Entity-Typ gehört § Ein UUID/GUID-Generator § Pro: kann auf dem Client ohne Verbindung zum Server erzeugt werden § Con: String in einem besonderen Format 34 17.12.20 //// Seite 39 WPS – Workplace Solutions VAUGHN VERNONS DAUMENREGELN FÜR AGGREGATES 1. Schütze fachliche Invarianten innerhalb von Aggregate-Grenzen. 2. Entwirf kleine Aggregates. 3. Referenziere andere Aggregates nur über ihre Identität. 4. Aktualisiere andere Aggregates unter Verwendung von Eventual Consistency. 39
  19. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 40 WPS –

    Workplace Solutions REGEL 1: SCHÜTZE FACHLICHE INVARIANTEN IN AGGREGATE-GRENZEN § Zusammensetzung der Aggregates vom Fachbereich bestimmen lassen § Grundlage: was muss konsistent sein, wenn der Commit einer Transaktion ausgeführt wird? § Das sind die fachlichen Invarianten § Meist braucht man viel weniger sofortige Konsistenz als man denkt! Aggregate Girokonto Girokonto Einzahlung 40 17.12.20 //// Seite 41 WPS – Workplace Solutions REGEL 2: ENTWIRF KLEINE AGGREGATES § Geringer Speicherbedarf § Kleiner Transaktionsumfang § SRP folgen § Mit Eine-Entity-Aggregates starten § Vorteile: § Schneller geladen § Performance § Leichter von Garbage Collection auzuräumen § Vor allem aber: Höhere Wahrscheinlichkeit, dass Transaktion erfolgreich abläuft Girokonto Kunde 41
  20. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 42 WPS –

    Workplace Solutions § Keine Referenzen auf Objekte § Nur Value Objects mit fachlicher Identität § Vorteile: § Hilft Aggregates klein zu halten § Schützt davor mehrere Aggregates in der gleichen Transaktion zu ändern § Leicht zu speichern auch in nicht-relationalen Persistenzmechanismen REGEL 3: REFERENZIERE ANDERE AGGREGATES NUR ÜBER IHRE IDENTITÄT Aggregate Kunde Kunde Kontonummer Aggregate Girokonto Girokonto Kontonummer 42 17.12.20 //// Seite 43 WPS – Workplace Solutions § Andere Aggregates müssen nicht sofort mit diesem konsistent sein § Es reicht, wenn sie irgendwann konsistent sind. § Implementierung gerne über Domain Events REGEL 4: AKTUALISIERE ANDERE AGGREGATES MIT EVENTUAL CONSISTENCY Aggregate Girokonto Girokonto Aggregate Girokonto Girokonto BetragÜberwiesen 43
  21. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 44 WPS –

    Workplace Solutions ÜBERWEISUNG – MIT EINEM SERVICE import org.jmolecules.ddd.annotation.Service; @Service public class CreditTransferService{ public void transfer(Account source, Account destination, Amount amount) { source.withdraw(amount); destination.deposit(amount); } } Keine Felder --> zustandslos 44 17.12.20 //// Seite 46 WPS – Workplace Solutions ZUSAMMENFASSUNG § Entities § Fachliche Umgangsformen statt Setter § Nimm Value Objects statt eingebauter Typen § Schütze Deine Methoden mit Verträgen § Benutze eine fachliche Identität § Value Objects § ausschließlich final Felder § Keine zustandsverändernden Operation § Aggregates § Möglichst klein § Nur über Identität referenzieren § Eventual Consistency 46
  22. IMPLEMENTIEREN DER BUILDING BLOCKS 17.12.20 //// Seite 47 WPS –

    Workplace Solutions ÜBUNG: MOBPROGRAMMING 47
  23. MICROSERVICES WPS – Workplace Solutions #dddkonkret www.wps.de MICROSERVICES Domain-Driven Design

    konkret 1 29.03.20 //// Seite 2 WPS – Workplace Solutions INHALT DOMÄNE DOMÄNE 2
  24. MICROSERVICES 29.03.20 //// Seite 3 WPS – Workplace Solutions ÜBERSICHT

    § Monolithen und Deployment § Microservices und Domäne § Microservices als Architekturstil § Skalierbarkeit 3 29.03.20 //// Seite 4 WPS – Workplace Solutions § Jede auch kleine Änderung erfordert ein Deployment des Gesamtsystems MONOLITHEN Foto: Jon/ficklr/CC BY-SA 2.0 4
  25. MICROSERVICES 29.03.20 //// Seite 5 WPS – Workplace Solutions MICROSERVICES

    – WAS IST DAS? § Ein Architekturstil und Modularisierungskonzept § MS können unabhängig voneinander deployt werden § Jeder MS hat seinen eigenen Datenhaushalt § Jeder MS ist ein eigener Prozess (oder sogar eine eigene VM) § MS müssen über ein Netz kommunizieren § Typisch: REST oder Messaging-Lösung § Sollte eigene GUI haben (à Self-Contained System) § Darf nicht größer als ein Team sein 5 29.03.20 //// Seite 6 WPS – Workplace Solutions MICROSERVICES – IT‘S ABOUT PEOPLE § Ein Art Teams aufzuteilen § àConways Law § Verwandte Begriffe: § Feature-Teams aus Scrum § Cross-Functional Teams Foto: Kaz/pixabay/CC0 6
  26. MICROSERVICES 29.03.20 //// Seite 7 WPS – Workplace Solutions CONWAYS

    LAW § Melvin Conway: "Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations." "If you have four groups working on a compiler, you'll get a 4-pass compiler“ Eric Raymond 7 29.03.20 //// Seite 12 WPS – Workplace Solutions MICROSERVICES – IT‘S ABOUT THE DOMAIN § Es bietet sich an, einen Microservice auf genau einen Bounded Context abbzubilden 12
  27. MICROSERVICES 29.03.20 //// Seite 13 WPS – Workplace Solutions WAS

    IST NICHT MICROSERVICES? § Team Client/ Team Server § Team UI, Team Backend, Team DB § èDas ist eine Aufteilung nach technischen Aspekten § Probleme: § Viele Abhängigkeiten, viel Kommunikation § Jedes neue Feature muss von allen Teams umgesetzt werden User Interface Database Business Logic 13 29.03.20 //// Seite 14 WPS – Workplace Solutions 14
  28. MICROSERVICES 29.03.20 //// Seite 15 WPS – Workplace Solutions Team

    Kopf Team Schwanz Team Rumpf Team Beine 15 29.03.20 //// Seite 16 WPS – Workplace Solutions Team Emma Team Berta Team Erna Team Lisl 16
  29. MICROSERVICES 29.03.20 //// Seite 17 WPS – Workplace Solutions VERWANDTE

    BEGRIFFE § DevOps § REST § Continuous Delivery § Docker § Spring Boot Foto: Matt Moor/flickr/CC BY-SA 2.0 17 29.03.20 //// Seite 18 WPS – Workplace Solutions MONOLITH FIRST * Komplexe Änderungen bleiben komplex – Einfache Änderungen bleiben einfach „Abstraktion einführen ist einfach – Abstraktion abschaffen ist schwer bis unmöglich“ Ausschneiden eines MS aus einem Monolithen ist nur möglich, wenn dieser eine fachliche Architektur hat èEs lohnt sich mit DDD zu starten 18
  30. MICROSERVICES 29.03.20 //// Seite 19 WPS – Workplace Solutions BOUNDED

    CONTEXT UND DEPLOYMENT Distributed Big Ball Of Mud Modulith Microservices Monolithic Big Ball Of Mud 19 29.03.20 //// Seite 21 WPS – Workplace Solutions MICROSERVICES ALS ARCHITEKTURSTIL Micro- service A Präsentations- Schicht Fachdomänen- Schicht Infrastruktur- Schicht Applikations- Schicht Micro- service B Präsentations- Schicht Fachdomänen- Schicht Infrastruktur- Schicht Applikations- Schicht Micro- service C Präsentations- Schicht Fachdomänen- Schicht Infrastruktur- Schicht Applikations- Schicht Technische Schichtung Fachliche Schichtung? 21
  31. MICROSERVICES 29.03.20 //// Seite 22 WPS – Workplace Solutions JEDER

    MICROSERVICES KANN EIGENE ARCHITEKTUR HABEN Micro- service A Präsentations- Schicht Fachdomänen- Schicht Infrastruktur- Schicht Applikations- Schicht Micro- service B Direkter Zugriff Auf die DB Micro- service C 22 29.03.20 //// Seite 26 WPS – Workplace Solutions MICROSERVICES – SKALIERBARKEIT 26
  32. MICROSERVICES 29.03.20 //// Seite 27 WPS – Workplace Solutions ZUSAMMENFASSUNG

    § Microservices führen zu unabhängiger Deploybarkeit § Microservices und Teamschnitt hängen eng zusammen § Bounded Context ist die ideale Grundlage für Microservice-Schnitt § Microservices skalieren besser als Monolithen 27 29.03.20 //// Seite 28 WPS – Workplace Solutions MODUL FLEX § Flexible Softwarearchitekturen § Microservices § DevOps § Continuous Delivery § Ab Oktober 2017 in Hamburg bei der WPS FLEX Flexible Softwarearchitekturmodelle Wie entwirft man besonders flexible Architekturen? 10 method. 20 techn. CP 28
  33. EVENT SOURCING UND CQRS WPS – Workplace Solutions #dddkonkret www.wps.de

    EVENT SOURCING UND CQRS Domain-Driven Design konkret 1 29.03.20 //// Seite 2 WPS – Workplace Solutions ÜBERSICHT § Event Sourcing § CQRS 2
  34. EVENT SOURCING UND CQRS 29.03.20 //// Seite 3 WPS –

    Workplace Solutions EVENT SOURCING § Klassische Speicherung von Aggregaten: § Der Zustand als Ganzes wird gespeichert § => Commands ändern Felder § Event Store § Die Zustandsänderungen (Ereignisse) werden gespeichert § => Commands appenden Events § Nur die Unterschiede § Append-only § Es gibt kein Löschen § Aber Stornierende Events § History-Funktion 3 29.03.20 //// Seite 4 WPS – Workplace Solutions EVENT SOURCING IM HAFEN § Klassische Implementierung: § Ändern der aktuellen Position § Event Sourced: § Merken der Verschiebungen und Drehungen Silhouette verschiebeUm(:Laenge) dreheUm(:Winkel) position Silhouette verschiebeUm(:Laenge) dreheUm(:Winkel) bewegungen() bewegungen <<DomainEvent>> SilhouetteGedreht winkel() <<DomainEvent>> SilhouetteVerschoben laenge() 4
  35. EVENT SOURCING UND CQRS 29.03.20 //// Seite 5 WPS –

    Workplace Solutions Fachliches vs. Technisches Event Sourcing Silhouette verschiebeUm(:Laenge) dreheUm(:Winkel) bewegungen() bewegungen Silhouette verschiebeUm(:Laenge) dreheUm(:Winkel) events() events VS 5 29.03.20 //// Seite 6 WPS – Workplace Solutions LEASINGVERTRAGS-BEISPIEL § Vertrag angelegt § Vertrag unterzeichnet § Vertrag genehmigt § (mit Auflagen) § Vertrag abgerechnet 6
  36. EVENT SOURCING UND CQRS 29.03.20 //// Seite 7 WPS –

    Workplace Solutions ÜBERSICHT § Event Sourcing § CQRS Udi Dahan 7 29.03.20 //// Seite 8 WPS – Workplace Solutions § CQS (Command-Query-Separation) § Operationen entweder zustandsändernd (Commands) § Oder sondierend (Queries) § CQRS (CQ-Responsibility-Segregation) § Trennung der Verantwortlichkeit § Zwei unterschiedliche Objekte/Module für Command und Query COMMAND-QUERY-RESPONSIBILITY-SEGREGATION (CQRS) Command Handler Query Handler Daten 8
  37. EVENT SOURCING UND CQRS 29.03.20 //// Seite 9 WPS –

    Workplace Solutions § Nur weil wir die gleichen Daten verwenden, müssen wir nicht das gleiche Datenmodell verwenden! COMMAND-QUERY-RESPONSIBILITY-SEGREGATION (CQRS) Command Handler Query Handler Datenmodell B Datenmodell A 9 29.03.20 //// Seite 10 WPS – Workplace Solutions § Die Commands werden in einer DB gespeichert § Die Queries werden auf einer anderen DB gefahren § Der Command Handler sorgt dafür, dass der Zustand der zweiten DB passend ist § Vorteile: § Unterschiedliche Technologien für CS und DB möglich § Dadurch schnelle Speicherung und schnelles Lesen § Historyfunktion § DB kann aus Command Store wiederhergestellt werden COMMAND STORE (AUCH: COMMAND SOURCING) Command Handler Query Handler Command Store Command Queue Query- Datenbank 10
  38. EVENT SOURCING UND CQRS 29.03.20 //// Seite 11 WPS –

    Workplace Solutions § “A command handler is a flavor of an application service“ ZWEITEILUNG VON DOMAIN- UND APPLICATION-LAYER Domain Model (Write Model) View Model (Read Model) Application Services for business tasks Application Services for report requests 11 29.03.20 //// Seite 12 WPS – Workplace Solutions CQRS UND FACHMODELLE § Queries § Können jetzt mit einem dünnen Lese-Layer gemacht werden § Keine Fachlogik mehr § èReporting § Commands § Behalten richtiges Fachmodell § Können aber schlanker sein, weil sie sich über Datenabfragen keine Gedanken mehr machen müssen § Typischerweise nur noch eine Abfrage getByID() 12
  39. EVENT SOURCING UND CQRS 29.03.20 //// Seite 13 WPS –

    Workplace Solutions EVENT-SOURCED CQRS Command Handler Thin Data Layer Event Store Client Reporting Database Domain Logic Event Repository Aggregate Command DTO Event Publisher Event Handler SQL 13 29.03.20 //// Seite 14 WPS – Workplace Solutions CQRS UND BOUNDED CONTEXTS § CQRS ist nicht für alles der richtige Architekturstil § Sondern in einzelnen Bounded Contexts § Auch möglich: § Command Handler in einem BC, § Query Handler in einem anderen Foto: Dawn Hudson/publicdomainpictures/CC0 14
  40. EVENT SOURCING UND CQRS 29.03.20 //// Seite 16 WPS –

    Workplace Solutions UNTERSCHIED EVENT/COMMAND § Command löst etwas aus § Event beschreibt etwas, das schon etwas geschehen ist 16
  41. WAM W PS – W orkplace Solutions #dddkonkret w w

    w .w ps.de WAM – DER WERKZEUG-UND-MATERIAL-ANSATZ Domain-Driven Design konkret 1 29.03.20 //// Seite 2 W PS –W orkplaceSolutions ÜBERSICHT 2 WAM 3 4 5 Entwurfsmetaphern 6 Foto: Dallas Museum of Art/Wikipedia 7 Foto: Christoph Michels/Wikipedia 8 Material 9
  42. WAM Foto: MrX/Wikipedia 10 Foto: Silsor/Wikipedia 11 Werkzeug 12 Material

    == passiv 17 Foto: Christoph Michels/Wikipedia 18 Foto: MrX/Wikipedia 19 == aktiv 20 21 22
  43. WAM Foto: Svdmolen/Wikipedia 23 24 Werkzeug zuhause in Domain und

    UI 25 Foto: Victor Blacus/Wikipedia 26 Interaktions- Komponente 27 28 Funktions- Komponente 29 30 31
  44. WAM 32 Foto: H. Schwentner 33 MVVM 34 35 WAM

    36 Foto: Rabe!/Wikipedia 37 Foto: Xocolatl/Wikipedia 38 29.03.20 //// Seite 39 W PS –W orkplaceSolutions ZUSAMMENFASSUNG 39
  45. IDEEN KOMMUNIZIEREN WPS – Workplace Solutions #dddkonkret www.wps.de IDEEN KOMMUNIZIEREN

    Domain-Driven Design konkret 1 29.03.20 //// Seite 3 WPS – Workplace Solutions FEARLESS CHANGE – PATTERNS § Evangelist § Accentuate the Positive § Elevator Pitch § Pick Your Battles § Low-Hanging Fruit § Do Food § Whisper in the General‘s Ear § Champions Skeptic § Study Group § ... 3
  46. IDEEN KOMMUNIZIEREN 29.03.20 //// Seite 4 WPS – Workplace Solutions

    HEADS, HEARTS, HANDS § Es reicht nicht, nur die logischen Zusammenhänge (Heads) zu erklären § Man muss auch § die Gefühle ansprechen (Hearts) § Zeigen, wie der einzelne mitmachen kann (Hands) Foto: Kenny sh/Wikipedia/CC BY-SA 3.0 Foto: Fibonacci/Wikipedia/CC BY-SA 3.0 Foto: OpenClipart-Vectors/pixabay/CC0 4 29.03.20 //// Seite 5 WPS – Workplace Solutions § Das bist Du! § Du hast eine gute Idee/Traum § To introduce a new idea, let your passion for this new idea drive you èAm Anfang geht es viel um Glauben EVANGELIST Foto: Russian Orthodox Church/Wikipedia/CC-PD-Mark 5
  47. IDEEN KOMMUNIZIEREN 29.03.20 //// Seite 6 WPS – Workplace Solutions

    ACCENTUATE THE POSITIVE § Drohe nicht mit dem was passiert, wenn die Idee nicht umgesetzt wird § Sage was besser wird „Dein Atem riecht besser“ statt „Wenn Du weiterrauchst, wirst Du an Krebs sterben“ 6 29.03.20 //// Seite 7 WPS – Workplace Solutions ELEVATOR PITCH § Habe parat: § Ein paar kurze Sätze, die anderen deine Idee vorstellen können § Einüben § Enthusiasmus rüberbringen Foto: Adam Kliczek/Wikipedia/CC-BY-SA-3.0 7
  48. IDEEN KOMMUNIZIEREN 29.03.20 //// Seite 8 WPS – Workplace Solutions

    § Bevor du Energie in einen Konflikt steckst, frag Dich, § ob du das Thema für wichtig genug hältst § Du genug Kraft hast, ihn bis zu Ende auszufechten PICK YOUR BATTLES Foto: Chroniques d’Enguerrand de Monstrelet/Wikipedia/CC-PD-Mark 8 29.03.20 //// Seite 9 WPS – Workplace Solutions LOW-HANGING FRUIT § Um den Fortschritt in der Initiative zu zeigen, mache eine Aufgaben fertig, die § Einfach fertigzustellen ist § Deutliche Auswirkungen hat § Sichtbar ist § Veröffentliche den Erfolg Foto: Luis Toro/flickr/CC BY 2.0 9
  49. IDEEN KOMMUNIZIEREN 29.03.20 //// Seite 10 WPS – Workplace Solutions

    § Du hast ein Meeting, in dem Du Deine Ideen vorstellen kannst § Mach das Meeting dadurch besonders, dass es Essen gibt è Nachteil: Die Forschung hat erwiesen: Je mehr Leute da sind, desto mehr essen wir ;-) DO FOOD 10 29.03.20 //// Seite 11 WPS – Workplace Solutions § Vorgesetzte überzeuge ich besser allein § In großen Meetings müssen sie ihr Gesicht wahren und Unwissenheit ist schwer zuzugeben WHISPER IN THE GENERAL‘S EAR Foto: The Yorck Project/Wikipedia/PD-old 11
  50. IDEEN KOMMUNIZIEREN 29.03.20 //// Seite 12 WPS – Workplace Solutions

    CHAMPION SKEPTIC Foto: Yi Chen/flickr/CC BY 2.0 12 29.03.20 //// Seite 13 WPS – Workplace Solutions STUDY GROUP 13
  51. IDEEN KOMMUNIZIEREN 29.03.20 //// Seite 14 WPS – Workplace Solutions

    § Sicher Dir die Unterstützung von jemand aus dem Management der § Besonderes Interesse an der Idee hat § Die Ressourcen bereitstellen kann § Kein Diktator sondern § Beschützer § Mentor § Thinking Partner CORPORATE ANGEL Foto: Wikipedia/PD-Art (PD-EU-anonymous) 14 29.03.20 //// Seite 15 WPS – Workplace Solutions ZUSAMMENFASSUNG 15