citerus / dddsample-core

This is the new home of the original DDD Sample app (previously hosted at sf.net)..
MIT License
4.94k stars 1.47k forks source link

Class under the domain/model path is "Anemia model"? #50

Open johnlee175 opened 3 years ago

johnlee175 commented 3 years ago

Like: class Cargo { public TrackingId trackingId() { return trackingId; } public Location origin() { return origin; } public Delivery delivery() { return delivery; } public RouteSpecification routeSpecification() { return routeSpecification; } }

Additional, I‘m newer, and I found Entity interface, why no Aggregate interface?

wtjones commented 3 years ago

The getters listed allow for private setters.

This pattern relates to anti-corruption of the domain model.

wtjones commented 3 years ago

In this example the aggregates are implied rather than explicit via interfaces. A matter of preference I suppose.

The domain layer is the heart of the software, and this is where the interesting stuff happens.
    There is one package per aggregate, and to each aggregate belongs entities, value objects, domain events,
    a repository interface and sometimes factories.

https://github.com/citerus/dddsample-core/blob/3576f879858f3ea5348a9e62c8f4ad296ff659f7/src/site/apt/architecture.apt#L31

johnlee175 commented 3 years ago

In this example the aggregates are implied rather than explicit via interfaces. A matter of preference I suppose.

The domain layer is the heart of the software, and this is where the interesting stuff happens.
  There is one package per aggregate, and to each aggregate belongs entities, value objects, domain events,
  a repository interface and sometimes factories.

https://github.com/citerus/dddsample-core/blob/3576f879858f3ea5348a9e62c8f4ad296ff659f7/src/site/apt/architecture.apt#L31

I see, thanks very much!

johnlee175 commented 3 years ago

The getters listed allow for private setters.

  • Location may only be set in the ctor.
  • Delivery is set in either the ctor or via specifyNewRoute().

This pattern relates to anti-corruption of the domain model.

specifyNewRoute() is ok. But here( application layer), CargoInspectionServiceImpl.java:

public class CargoInspectionServiceImpl implements CargoInspectionService {
// ...
    if (cargo.delivery().isMisdirected()) {
      applicationEvents.cargoWasMisdirected(cargo);
    }

    if (cargo.delivery().isUnloadedAtDestination()) {
      applicationEvents.cargoHasArrived(cargo);
    }
// ...
}

is the following approach bad? (Law of Demeter, Encapsulate logic to the target object)

public class CargoInspectionServiceImpl implements CargoInspectionService {
// ...
    cargo.misdirectedIfNeeds(); // and publish event in domain
// ... or
    if (cargo.isUnloadedAtDestination()) { // should application know delivery?
      applicationEvents.cargoHasArrived(cargo);
    }
// ...
}