Effizientes Gerätedesign. Einzelstücksimulation

Dieser Artikel ist eine Zusammenfassung des effektiven Aggregatdesigns Teil I: Modellieren eines einzelnen Aggregats .





Das Kombinieren von Entitäten und Wertobjekten zu einem Aggregat mit sorgfältig durchdachten Konsistenzgrenzen mag einfach erscheinen, aber von allen taktischen DDD-Mustern ist das Aggregat eines der komplexesten.





Es wird hilfreich sein, mit einigen allgemeinen Fragen zu beginnen. Ist ein Aggregat nur eine Möglichkeit, eng verwandte Objekte mit einer gemeinsamen Wurzel (Aggregatwurzel) zu kombinieren? Wenn ja, gibt es eine Beschränkung für die Anzahl der Objekte, die im Diagramm enthalten sein können? Ist es möglich, mithilfe dieser Links durch die Aggregate zu navigieren und die Daten der in einem bestimmten Aggregat enthaltenen Objekte zu ändern, da ein Aggregat auf ein anderes verweisen kann? Und was ist die Invarianten- und Konsistenzgrenze ? Die Antwort auf die letzte Frage beeinflusst weitgehend den Rest der Antworten.





Es gibt viele Möglichkeiten, eine Baugruppe falsch zu modellieren. Wir können eine Einheit entwerfen, die zu groß ist. Andererseits können wir alle Aggregate so teilen, dass dadurch die wahren Invarianten verletzt werden. Wie wir sehen werden, ist es unerlässlich, solche Extreme zu vermeiden und stattdessen die Geschäftsregeln zu beachten.





ProjectOvation-Anwendungsentwicklung

Schauen wir uns die Aggregate anhand eines Beispiels an. Unser fiktives Unternehmen entwickelt eine Anwendung zur Unterstützung von Projekten, die auf der Scrum-Methodik basieren. Die Anwendung folgt dem traditionellen Scrum-Projektmanagementmodell, dh es gibt ein Produkt (Produkt), einen Product Owner (Product Owner), Teams (Team), Backlog-Elemente (Backlog-Elemente), geplante Releases (geplante Releases) und Sprints ( Sprints). Die Scrum-Terminologie bildet den Ausgangspunkt einer allgegenwärtigen Sprache. Jede Organisation, die ein Abonnement kauft, registriert sich als Mieter, ein anderer Begriff für unsere gemeinsame Sprache .





. , DDD . , , DDD . , . , .





? . , . . :





  • , .





  • .





  • .





  • .





  • .





  • .





. , .





:

« » . , , . :





  • , .





  • , .





  • , .





  • , .





Product . , Product, BacklogItem, Release, Sprint , . . UML- .





public class Product extends ConcurrencySafeEntity {

    private Set<BacklogItem> backlogItems;
    private String description;
    private String name;
    private ProductId productId;
    private Set<Release> releases;
    private Set<Sprint> sprints;
    private TenantId tenantId;
    ...

}

      
      



Zahl:  1. Das Produkt wird als sehr große Baugruppe modelliert.
. 1. Product .

, - . , .  , . , , . () , .





:





  • , , Product c 1 .





  • BacklogItem . 2.





  • Release , , Product 1.





. .





. , . . .





. ? , -. , . , .





:

, 2. . ProductId, Product-.





Zahl:  2. Produkt- und verwandte Konzepte werden als separate Aggregate modelliert.
. 2. Product .

Product. :





public class Product ... {
    	...
      public void planBacklogItem(
        String aSummary, String aCategory,
        BacklogItemType aType, StoryPoints aStoryPoints) {
      		...
      }
    	...
      public void scheduleRelease(
        String aName, String aDescription,
        Date aBegins, Date anEnds) {
      		...
      }

      public void scheduleSprint(
        String aName, String aGoals,
        Date aBegins, Date anEnds) {
        	...
      }
      ...
}

      
      



. Product, , – void. :





public class Product ... {
    	...
      public BacklogItem planBacklogItem(
        String aSummary, String aCategory,
        BacklogItemType aType, StoryPoints aStoryPoints) {
      		...
      }
  
      public Release scheduleRelease(
        String aName, String aDescription,
        Date aBegins, Date anEnds) {
        	...
      }

      public Sprint scheduleSprint(
        String aName, String aGoals,
        Date aBegins, Date anEnds) {
        	...
      }
      ...
}

      
      



. . , , :





public class ProductBacklogItemService ... {
     ...
     @Transactional
     public void planProductBacklogItem(
           String aTenantId, String aProductId,
           String aSummary, String aCategory,
           String aBacklogItemType, String aStoryPoints) {

           Product product =
                   productRepository.productOfId(
                                 new TenantId(aTenantId),
                                new ProductId(aProductId));

           BacklogItem plannedBacklogItem =
                  product.planBacklogItem(
                            aSummary,
                            aCategory,
                            BacklogItemType.valueOf(aBacklogItemType),
                            StoryPoints.valueOf(aStoryPoints));
          
          backlogItemRepository.add(plannedBacklogItem);
      }
      ...
}

      
      



, . BacklogItem, Release Sprint .





. , , . , , , - . , , .





, . , .





— -, . . , . . . :





c = a + b

, , = 2 b = 3, 5. , 5, . , , .





AggregateType1 {
    int a; int b; int c;
    operations...
}

      
      



, , , - , . , , . , .





. , , . – , , , , . .





( ) . .





, , , . , . . . , , .





: ? , , . , , , , , . - , .





, , ? , (lazy loading). , . , , . , . , , . , .





, 3. 0..* . . , . . , , . .





Zahl:  3. Produktmodell.  Während vieler einfacher Vorgänge werden mehrere große Sammlungen geladen.
. 3. Product. .

. , , .





, , «». , , , . , (root entity), / (object value).





, (, ) ? : , . , Product name description. , . , , . -, .





, , , . , , . , , , . , . . - , .





. , . , . , . Order OrderItem . , - , . , .





, , . . , , , .





, . , - . , . , . , , .





, -, , - , . 4. , , , . . , . , , , -.





Zahl:  4. Zeigt den gleichzeitigen Zugriff auf Daten zwischen drei Benutzern an.  Sie versuchen, auf dieselben zwei Instanzen von Aggregaten zuzugreifen, was zu einer großen Anzahl von Transaktionsfehlern führt.
. 4. . , .

, , . , , . ?





, , , , . - (eventual consistency) . , , , . , , . . , .








All Articles