domain-driven design with seedstack

14
Domain-Driven Design with SeedStack business framework Adrien LAUER http://seedstack.org

Upload: seedstack

Post on 18-Feb-2017

200 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Domain-Driven Design with SeedStack

Domain-Driven Design with SeedStack business framework

Adrien LAUERhttp://seedstack.org

Page 2: Domain-Driven Design with SeedStack

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

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

Levels of abstraction

Annotations

Interfaces

Base classes

Low framework couplingLow speed

High framework couplingHigh speed

Page 5: Domain-Driven Design with SeedStack

Building blocks

Page 6: Domain-Driven Design with SeedStack

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

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

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

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

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

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

More…

Domain policies

Domain events

DTO/Aggregate assembling

Finders and pagination

Page 13: Domain-Driven Design with SeedStack

Demo

https://github.com/adrienlauer/nightclazz-ddd-sample

Page 14: Domain-Driven Design with SeedStack

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