not your father s
play

Not your Fathers @ mobile Larson @ _open Knowledge Java EE Lars - PowerPoint PPT Presentation

Not your Fathers @ mobile Larson @ _open Knowledge Java EE Lars Rwekamp | CIO New Technologies May I submit my billing info to your merchant account via your payment gateway ? Wo liegt das Problem ... Too many times


  1. Not your Father’s 
 @ mobile Larson 
 @ _open Knowledge Java EE Lars Röwekamp | CIO New Technologies

  2. „May I submit my billing info to your merchant account via your payment gateway ?“

  3. Wo liegt das Problem ... „Too many times application architects focus on the technical problems instead of designing for the problem domain.“

  4. Wo liegt das Problem ... UI User Interface App CDI Managed Bean TX Service Session EJB Session EJB Data Entity EntityManager

  5. Es wäre doch viel schöner, wenn ... UI User Interface App UseCase Controller TX Business Object Business Object Domain Business Object

  6. Es wäre doch viel schöner, wenn ... Business UI User Interface TX App UseCase Controller Business Object Business Object Domain Business Object

  7. Es wäre doch viel schöner, wenn ... Application Adapter Adapter Domain Model

  8. Es wäre doch viel schöner, wenn ... App Core mit Business TX Application Adapter Adapter Domain Model

  9. Es könnte alles so einfach sein ...

  10. Das kleine 1x1 des DDD … Eric Evans says „For most software projects, the primary focus should be on the domain and domain logic .“ „Complex domain design should be based on a model .“

  11. Das kleine 1x1 des DDD … fachliche Domäne End User Die gemeinsame fachliche Welt in der wir „leben“. Domain Technical Expert Expert

  12. Das kleine 1x1 des DDD … Ubiquitous Language End User Fachsprache als Basis 
 für ein gemeinsames Domain Model Domain Technical Expert Expert

  13. Das kleine 1x1 des DDD … Rich Domain Model End User „Produce Software 
 that makes perfectly 
 sense to business , 
 Domain Technical not only to coder“ Expert Expert

  14. Das kleine 1x1 des DDD … Rich Domain Model Access Layer „Produce Software 
 that is always 
 Business Layer in a correct state , 
 Domain Technical not only partially“ Expert Expert DB Layer

  15. Das kleine 1x1 des DDD … Repositories access with Services access with maintain integrity with Entities express model with act as root of express model with Aggregates express model with Value Objects Model-Driven Design encapsulate with encapsulate with encapsulate with isolate domain with X mutually exclusive encapsulate with choices Factories Layered Architecture Smart UI

  16. Das kleine 1x1 des DDD … keep model unified by Continous Shared Integration Kernel Bounded Context Customer names Supplier Overlap allied contexts through enter Teams relate allied contexts as assess/overview Context Map relationships with overlap unilaterally as Conformist support multiple Ubiquitous clients through Language Open Host free teams to go Service formalize as Published translate and insulate Language unilaterally with Separate Ways Anticorruption Layer

  17. Passt das zu Java EE?

  18. Passt das zu Java EE? Klar … Java EE Next Generation BluePrint a.k.a. Java EE meets DDD

  19. Passt das zu Java EE? Klar …

  20. Passt das zu Java EE? Klar, aber … You must follow the „Chuck-Norris“ Rules!

  21. Always follow the Rules … RULE #1 Design a Rich not an Anemic Domain Model

  22. Rule #1: Rich not Anemic Domain Model /** * Represents a business customer with a * full qualified name, a date of birth indicating * if the customer is „sui juris“ and a valid address * that may change after a relocation. */ Fachlichkeit? public class Customer { private String firstName; private String lastName; private Date birthDate; private Address address; public void setFirstName(String aFirstName) { ... } public String getFirstName() { return firstName; } public void setLastName(String aLastName) { ... } public String getLastName() { return lastName; } public void setBirthDate(Date birthDate) { ... } public Date getBirthDate() { return birthDate; } public void setAddress(Address address) { ... } public Address getAddress() { return address; } }

  23. Rule #1: Rich not Anemic Domain Model /** * Represents a customer data access object to sprechend? * encapsulate all db relevant activities */ public class CustomerDao { ... public List<Customer> findByZipCodeOrCity( String zipCode, String city) { return ...; } public List<Customer> findByZipCodeOrCityOrCityLimit( String zipCode, String city, int order) { return ...; } }

  24. Rule #1: Rich not Anemic Domain Model Zur Erinnerung „Wir möchten ein sprechendes Domain Model , mit einem sprechenden API , welches wir in sich konsistent erzeugen und im weiteren Verlauf konsequent konsistent erhalten .“

  25. Rule #1: Rich not Anemic Domain Model Anforderungen ‣ sprechendes Modell ‣ sprechendes API ‣ konsistent erzeugen ‣ konsistent erhalten ‣ Fachlichkeit, Validierung, Konvertierung, Normalisierung und Konsistenzprüfung!

  26. Mut zur Fachlichkeit

  27. Rule #1: Rich not Anemic Domain Model Anforderungen ‣ sprechendes Modell ‣ sprechendes API ‣ konsistent erzeugen ‣ konsistent erhalten

  28. Rule #1: Rich not Anemic Domain Model sprechend // (JPA) Entity with Value Objects public class Customer extends HumanBeing { private FirstName firstName; private LastName lastName; private FamilyStatus familyStatus; private Customer partner; private Address postalAddress; private Map< PhoneNumberType, PhoneNumber > phoneNumbers; ... public void marry(Partner partner,LastName newLastName) { lastName = notNull(newLastName) familyStatus = FamilyStatus.MARRIED; // Ensure bidirectional integrity for partner entity! ... } public boolean isMarried() { return (familyStatus == FamilyStatus.MARRIED ); } }

  29. Rule #1: Rich not Anemic Domain Model sprechend // (JPA) Entity with Value Objects public class Customer extends HumanBeing { ... private Map< PhoneNumberType , PhoneNumber > phoneNumbers; ... public void changeHomePhoneNumber ( PhoneNumber changedHomePhoneNumber) { ... } public void disconnectHomePhone () { ...} public void changeMobilePhoneNumber ( PhoneNumber changedHomePhoneNumber) { ... } public void disconnectMobilePhone () { ... } ... }

  30. Rule #1: Rich not Anemic Domain Model /** * Represents a customer data access object to sprechend * encapsulate all db relevant activities */ public class CustomerDao { ... public List<Customer> findByZipCodeOrCityOrStreet( String street, String city, String zipCode) { return ...; } public List<Customer> findByAnyOf( ZipCode zipCode, City city, Street order) { return ...; } }

  31. Hmm, passt das wirklich zu Java EE?

  32. Rule #1: Rich not Anemic Domain Model /** * Simple value object for first name using the * common base <code>SimpleValueObject</code> */ public class FirstName extends SimpleValueObject<String> { public FirstName(String aValue) { super(aValue); } Common Base public String getText() { return super.getValue(); } } ‣ Passt das wirklich: Value Objects ?

  33. Rule #1: Rich not Anemic Domain Model /** Abstract value object as a common base */ public abstract class SimpleValueObject<T extends Comparable> 
 implements Serializable, Comparable<SimpleValueObject<T>> { private T value; public SimpleValueObject(T aValue) { value = aValue; } protected T getValue() { return value; } Common Base public boolean equals(Object o) { return ...; } public int hashCode() { return ...; } public String toString() { return ...; } public int compareTo(SimpleValueObject<T> o) { return ...; } }

  34. Rule #1: Rich not Anemic Domain Model /** * Embeddable date of birth for (re)use in value objects */ @Embeddable public class DateOfBirth { private Date dateOfBirth; VO, Entities & JPA ... } /** * Customer entity making use of date of birth embeddable */ @Entity public class Customer { @Embedded @AttributeOverride(name=„dateOfBirth", column=@Column(name=“CUST_BIRTHDATE“)) private DateOfBirth dateOfBirth; ... }

  35. Rule #1: Rich not Anemic Domain Model VO & JPA Queries /** * Using JPA-QL and ValueObjects */ @Entity @Table(name = "TAB_USER", ...) @NamedQueries({ @NamedQuery(name = "User.findByEmail", query = " select u from User u where u.email = :email "), @NamedQuery(name = "User.findByEmailString", query = "select u from User u " + " where u.email.value = :emailString“) }) public class User extends AbstractEntity { protected static final String EMAIL_COLUMN = "EMAIL"; @AttributeOverride(name = "value", column = @Column(name = EMAIL_COLUMN, unique = true, nullable = false)) private Email email; ... }

  36. Rule #1: Rich not Anemic Domain Model /** CDI based JSF Controller managing user related input */ @Named("customerController") @RequestScoped public class CustomerController { private DateOfBirth dateOfBirth; private ZipCode zipCode; ...; public DateOfBirth getDateOfBirth() { return dateOfBirth; } public void setDateOfBirth(DateOfBirth newDateOfBirth) { dateOfBirth = newDateOfBirth; } public ZipCode getZipCode() { return zipCode; } VO & JSF public void setZipCode(ZipCode newZipCode) { zipCode = newZipCode; } ... }

Recommend


More recommend