domain-driven design with seedstack
TRANSCRIPT
![Page 1: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/1.jpg)
Domain-Driven Design with SeedStack business framework
Adrien LAUERhttp://seedstack.org
![Page 2: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/2.jpg)
OverviewSeedStack is a full-stack development solution– Java backend–Web frontend
The business framework aims to make implementing DDD easier:
– A set of tactical building blocks– Common tasks automation– Helpers
![Page 3: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/3.jpg)
Business frameworkBased on SeedStack Java framework– Classpath scanning with detection of code
patterns– Dependency injection with Guice
Extensible through add-ons: – JPA, – MongoDB, – …
![Page 4: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/4.jpg)
Levels of abstraction
Annotations
Interfaces
Base classes
Low framework couplingLow speed
High framework couplingHigh speed
![Page 5: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/5.jpg)
Building blocks
![Page 6: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/6.jpg)
Entitiespublic class Customer extends BaseEntity<String> {
private String email; private Address address;
public Customer (String email) { this.email = email;
}
@Override public String getEntityId() {
return this.email; }
// … more}
Features:• Equals() and hashCode()• Simple toString()
Alternatives:• Implement Entity• Annotate with @DomainEntity
![Page 7: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/7.jpg)
Value Objectspublic class Address extends BaseValueObject {
private final String street; private final String city; private final ZipCode zipCode;
public Address(String street, String city, ZipCode zipCode) {
this.street = street; this.city = city; this.zipCode = zipCode;
}
// … more}
Features:• Equals() and hashCode()• Simple toString()
Alternatives:• Implement ValueObject• Annotate with
@DomainValueObject
![Page 8: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/8.jpg)
Aggregatespublic class Order extends BaseAggregateRoot<OrderId> {
private OrderId orderId; private Date checkoutDate; private double totalPrice;
public Order(OrderId orderId) { this.orderId = orderId; }
@Override public OrderId getEntityId() { return this.orderId ; }
// … more}
Features:• Equals() and hashCode()• Simple toString()
Alternatives:• Implement AggregateRoot• Annotate with
@DomainAggregateRoot
![Page 9: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/9.jpg)
ServicesDefine an interface:
@Service public interface CheckoutService { public Invoice checkout(Order order); }
And one or more implementation(s):@Named(“creditCard")public class CreditCardCheckoutService implements CheckoutService { @Override public Invoice checkout(Order order) { ... } }
Qualifies implementation if there are multiple ones
![Page 10: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/10.jpg)
RepositoriesBasic repositories without effort:
@Inject @Jpa private Repository<Customer, String> customerRepository;
Can be extended with custom methods:
public interface CustomerRepository extends GenericRepository<Customer, String> { List<Customer> findByName(String firstName, String lastName); }
@Jpapublic class CustomerJpaRepository extends BaseJpaRepository<Customer, String> implements CustomerRepository { @Override public List<Customer> findByName (String firstName, String lastName) { ... } }
Also available with other technologies
Qualifies implementation if there are multiple ones
![Page 11: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/11.jpg)
FactoriesConstructor-based factories without effort:
@Injectprivate Factory<Customer> customerFactory;
Can be extended with custom methods:
public interface CustomerFactory extends GenericFactory<Customer> { Customer createCustomer(String email, String firstName, String lastName);}
public class CustomerFactoryImpl extends BaseFactory<Customer> implements CustomerFactory { @Override public Customer createCustomer(String email, String firstName, String lastName) { ... } }
Can be plugged in with identity generators (provided or custom)
![Page 12: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/12.jpg)
More…
Domain policies
Domain events
DTO/Aggregate assembling
Finders and pagination
![Page 13: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/13.jpg)
Demo
https://github.com/adrienlauer/nightclazz-ddd-sample
![Page 14: Domain-Driven Design with SeedStack](https://reader031.vdocuments.us/reader031/viewer/2022030202/58a764d71a28ab217e8b6761/html5/thumbnails/14.jpg)
Join us !Documentation: http://seedstack.org
Code on GitHub: https://github.com/seedstack
News on Twitter: @seedstack
Questions on SO:http://stackoverflow.com/questions/tagged/seedstack
Talk on IRC: #seedstack on freenode