値オブジェクトの悩みポイントとどう付き合っていくか

D98762c822b683773188e826a00d243e?s=47 yachiy
July 30, 2019

 値オブジェクトの悩みポイントとどう付き合っていくか

D98762c822b683773188e826a00d243e?s=128

yachiy

July 30, 2019
Tweet

Transcript

  1. 4.
  2. 8.

    public class PersonName { private String firstName; private String lastName;

    public String fullName() { return String.format("%s %s", firstName, lastName); } } ͜ͷ͘Β͍ͳΒಛʹ೰·ͳ͍ ྫͷࢀরݩɿ
  3. 9.

    public class PersonName { private String firstName; private String lastName;

    public String fullName() { return String.format("%s %s", firstName, lastName); } } ݸผͷৼΔ෣͍͸ͳͦ͞͏ͳͷͰಛʹ೰·ͳ͍
  4. 10.

    public class PersonName { private String firstName; private String lastName;

    private String middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } }
  5. 11.

    public class PersonName { private String firstName; private String lastName;

    private String middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } ໊ࣈɺ໊લͱ͸ໟ৭͕ҧ͏ ˠݸผͷৼΔ෣͍͕͋Γͦ͏ ˠཁૉͷ஋ΦϒδΣΫτԽΛݕ౼
  6. 12.

    public class MiddleName { private static final int MIN_LENGTH =

    1; private static final int MAX_LENGTH = 100; // null͕ೖΒͳ͍͜ͱ͸ݕূ͞Ε͍ͯΔ૝ఆ → ࢦఆ͕ͳ͍͜ͱ͸ۭจࣈͰදݱ private String value; // ίϯετϥΫλ΍ੜ੒ϝιουͰݕূ͢Δ͔ར༻ଆͰݕূ͔ͯ͠Β౉͔͢͸·ͨผͷ೰ΈϙΠϯτ… ... // ඞཁʹԠͯ͡༻ҙ public boolean isSpecified() { // value͕ۭจࣈͰͷੜ੒͸ڐͯ͠΋nullͰͷੜ੒͸ڐ͞ͳ͍ඞཁ͋Γ return !value.isEmpty(); } @Override public String toString() { return value; } ... }
  7. 13.

    public class MiddleName { private static final int MIN_LENGTH =

    1; private static final int MAX_LENGTH = 100; // null͕ೖΒͳ͍͜ͱ͸ݕূ͞Ε͍ͯΔ૝ఆ → ࢦఆ͕ͳ͍͜ͱ͸ۭจࣈͰදݱ private String value; // ίϯετϥΫλ΍ੜ੒ϝιουͰݕূ͢Δ͔ར༻ଆͰݕূ͔ͯ͠Β౉͔͢͸·ͨผͷ೰ΈϙΠϯτ… ... // ඞཁʹԠͯ͡༻ҙ public boolean isSpecified() { // value͕ۭจࣈͰͷੜ੒͸ڐͯ͠΋nullͰͷੜ੒͸ڐ͞ͳ͍ඞཁ͋Γ return !value.isEmpty(); } @Override public String toString() { return value; } ... } ໊લ΍໊ࣈʹ΋ಉ༷ͷੑ࣭͸͋Γͦ͏ ˠ4USJOH͔Β஋ΦϒδΣΫτԽΛݕ౼ͯ͠΋ྑͦ͞͏ ஋ͷൣғΛ੍ݶͯ͠ ϓϩάϥϜΛΘ͔Γ ΍҆͘͢શʹ
  8. 14.

    public class MiddleName { private static final int MIN_LENGTH =

    1; private static final int MAX_LENGTH = 100; // null͕ೖΒͳ͍͜ͱ͸ݕূ͞Ε͍ͯΔ૝ఆ → ࢦఆ͕ͳ͍͜ͱ͸ۭจࣈͰදݱ private String value; // ίϯετϥΫλ΍ੜ੒ϝιουͰݕূ͢Δ͔ར༻ଆͰݕূ͔ͯ͠Β౉͔͢͸·ͨผͷ೰ΈϙΠϯτ… ... // ඞཁʹԠͯ͡༻ҙ public boolean isSpecified() { // value͕ۭจࣈͰͷੜ੒͸ڐͯ͠΋nullͰͷੜ੒͸ڐ͞ͳ͍ඞཁ͋Γ return !value.isEmpty(); } @Override public String toString() { return value; } ... } όϦσʔγϣϯΛͲ͜ʹஔ͔͘͸·ͨผͷ೰ΈϙΠϯτ
  9. 15.

    public class MiddleName { private static final int MIN_LENGTH =

    1; private static final int MAX_LENGTH = 100; // null͕ೖΒͳ͍͜ͱ͸ݕূ͞Ε͍ͯΔ૝ఆ → ࢦఆ͕ͳ͍͜ͱ͸ۭจࣈͰදݱ private String value; // ίϯετϥΫλ΍ੜ੒ϝιουͰݕূ͢Δ͔ར༻ଆͰݕূ͔ͯ͠Β౉͔͢͸·ͨผͷ೰ΈϙΠϯτ… ... // ඞཁʹԠͯ͡༻ҙ public boolean isSpecified() { // value͕ۭจࣈͰͷੜ੒͸ڐͯ͠΋nullͰͷੜ੒͸ڐ͞ͳ͍ඞཁ͋Γ return !value.isEmpty(); } @Override public String toString() { return value; } ... } Ͳ͏ͯ͠΋ར༻ଆͰ஋ͷ͋Δͳ͠Λؾʹ͢ΔͳΒ࣮૷
  10. 16.

    public class PersonName { private FirstName firstName; private LastName lastName;

    private MiddleName middleName; ... public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } }
  11. 17.

    public class PersonName { private FirstName firstName; private LastName lastName;

    private MiddleName middleName; ... public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } ͜͜·Ͱຖճࡉ͔͘஋ΦϒδΣΫτԽ͢Δͷ͔
  12. 18.

    public class PersonName { private String firstName; private String lastName;

    private String middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } public class PersonName { private FirstName firstName; private LastName lastName; private MiddleName middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } }
  13. 19.

    public class PersonName { private String firstName; private String lastName;

    private String middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } public class PersonName { private FirstName firstName; private LastName lastName; private MiddleName middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } public class PersonName { private static final int MIN_FIRST_NAME_LANGTH = 1; private static final int MAX_FIRST_NAME_LENGTH = 100; private static final int MIN_MIDDLE_NAME_LENGTH = 1; private static final int MAX_MIDDLE_MAME_LENGTH = 100; private static final int MIN_LAST_NAME_LENGTH = 1; private static final int MAX_LAST_NAME_LENGTH = 100; private String firstName; private String lastName; private String middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } ্Ґ֓೦͕ߏ੒ཁૉͷ ஋ͷൣғΛ୲อ
  14. 20.

    public class PersonName { private static final int MIN_FIRST_NAME_LANGTH =

    1; private static final int MAX_FIRST_NAME_LENGTH = 100; private static final int MIN_MIDDLE_NAME_LENGTH = 1; private static final int MAX_MIDDLE_MAME_LENGTH = 100; private static final int MIN_LAST_NAME_LENGTH = 1; private static final int MAX_LAST_NAME_LENGTH = 100; private String firstName; private String lastName; private String middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } public class PersonName { private String firstName; private String lastName; private String middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } public class PersonName { private FirstName firstName; private LastName lastName; private MiddleName middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } public class PersonName { private FirstName firstName; private LastName lastName; private MiddleName middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } ্Ґ֓೦͕ߏ੒ཁૉͷ ஋ͷൣғΛ୲อ ಛʹมΘΓͳ͠
  15. 23.

    public class PersonName { private static final int MIN_FIRST_NAME_LANGTH =

    1; private static final int MAX_FIRST_NAME_LENGTH = 100; private static final int MIN_LAST_NAME_LANGTH = 1; private static final int MAX_LAST_NAME_LENGTH = 100; private String firstName; private String lastName; private MiddleName middleName; public String fullName() { return String.format("%s %s %s", firstName, middleName, lastName); } } ϛυϧωʔϜ͚͕ͩಛघͱ͍͏ҙਤ͸఻ΘΓͦ͏ ཧղͷෛՙ͸ߴͦ͏