Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ドメイン駆動設計を軽快に実践するための工夫

haljik
March 05, 2016

 ドメイン駆動設計を軽快に実践するための工夫

DDD関西.java 3/5(土) 発表資料

haljik

March 05, 2016
Tweet

More Decks by haljik

Other Decks in Technology

Transcript

  1. എܠ 4 WebΞϓϦέʔγϣϯ։ൃ 4 Java 4 Spring Boot 4 Thymeleaf

    4 MyBatis H2database & PostgreSQL 4 ։ൃϝϯόʔ͸࠷େͰ΋10ਓ͙Β͍ͷن໛ײ
  2. 2. ϢʔεέʔεͷςετΛॻ͘ @Autowired UserRegisterService service; def "ར༻ऀΞΧ΢ϯτͷ৽نొ࿥"() { given: def

    newUser = new User(); when: "ొ࿥͢Δ" service.register(newUser); then: "ొ࿥Ͱ͖Δ" noExceptionThrown(); }
  3. 4. σʔλιʔεͷ࣮૷ public interface UserRepository { void register(User user); }

    @Repository public class UserDataSource implements UserRepository { //...ུ }
  4. 5. ϓϨθϯςʔγϣϯͷ࣮૷ @Controller public class UserRegisterController { //ొ࿥ը໘ͷදࣔ //ొ࿥ }

    <h1>Ϣʔβʔొ࿥<h1> <form th:action="@{/users/}" method="post"> <input type="submit" value="ొ࿥͢Δ"/> </form>
  5. 2ͷ࣮૷ྫ ར༻ऀϞσϧ public class User { //ར༻ऀ UserId id; ...

    Profile profile; //ݸਓ৘ใ ResponsibleArea area; //୲౰ΤϦΞ }
  6. 2ͷ࣮૷ྫ(ଓ͖) ݸਓ৘ใߋ৽࣌ͷґཔΦϒδΣΫτ public class ProfileUpdateRequest { User old; //ू໿ϧʔτΛ๊͑ͯ͠·͏ Profile

    update; } ୲౰ΤϦΞߋ৽࣌ͷґཔΦϒδΣΫτ public class ResponsibleAreaUpdateRequest { User old; //ू໿ϧʔτΛ๊͑ͯ͠·͏ ResponsibleArea area; }
  7. 2ͷ࣮૷ྫ(ଓ͖) ར༻ऀαʔϏε @Service public UserRegisterService { @Autowired UserRepository repository; public

    void register(User user) { repository.register(user); //ొ࿥͸·Δͬͱ } public void updateProfile(ProfileUpdateRequest request) { repository.register(request); //ϦϙδτϦ͸ΠϕϯτͷੵΈ্͛ } public void updateResponsibleArea(ResponsibleAreaRequest request) { repository.register(request); //ϦϙδτϦ͸ΠϕϯτͷੵΈ্͛ } }