2023.02.03
π‘ λμ μ½λλ‘ νλ‘κ·Έλλ¨Έκ° μΉλ₯΄λ κ³ ν΅
π‘ κΉ¨λν μ½λλ?
class Product {}
class ProductData {}
class ProductInfo {}
getActiveAccount()
getActiveAccounts() // μ¬λ¬κ° 리ν΄μ΄ νμν μ μλλ°, μ΄λ»κ² λ³κ²½νλ©΄ μ’μκΉ?
getActiveAccountInfo()
ex 1)
ex 2)
ex 3)
π
firstName, lastName, street, houseNumber, city
β addrFirstName, arrdLastName, addrState
β Address Class μμ±
π‘ λ€μ΄λ° κ·Έκ±° μ΄λ»κ² μ ν μ μλλ°μ..?
β DealService.process(events)
λκ° : λ μλΉμ€κ°.
μ΄λ»κ² : μ²λ¦¬νλ€.
무μμ : μ΄λ²€νΈλ€μ.
operationμ λ°λΌμ μ²λ¦¬κ° λ¬λΌμ§.
β SpecialShopMatchService.processCreate(events)
λκ° : νΉκ°μ΅ λ§€μΉ μλΉμ€κ°.
μ΄λ»κ² : μ²λ¦¬νλ€.
무μμ : μ΄λ²€νΈλ€μ μμ±μ.
Link Typeμ λ°λΌμ μ²λ¦¬κ° λ¬λΌμ§.
β SpecialShopMatchService.processTourTicketCreate(events)
λκ° : νΉκ°μ΅ λ§€μΉ μλΉμ€κ°.
μ΄λ»κ² : μ²λ¦¬νλ€.
무μμ : ν¬μ΄ν°μΌ μ΄λ²€νΈλ€μ μμ±μ.
π
π‘ ν κ°μ§μ λ²μκ° λλ°μ..?
public Mony caculatePay(Employee e) throws InvalidEmployeeType{
switch (e.type) {
case COMMISSIONED:
return calculateCommissionedPay(e);
case HOURLY:
return calculateHourlyPay(e);
case SALARIED:
return calculateSalariedPay(e);
default:
throw new InvalidEmployeeType(e.type);
}
}
<aside>
π‘ ν΄λμ€λ νλμ μ±
μλ§ κ°μ§λ©°, ν΄λμ€λ κ·Έ μ±
μμ μμ ν μΊ‘μν ν΄μΌν¨.
</aside>
μ±
μ : λ³κ²½νλ €λ μ΄μ
[JPA μμ](https://stackify.com/solid-design-principles/)
public abstract class Employee {
public abstract boolean isPayday();
public abstract Money calculatePay();
public abstract void deliveryPay(Money pay);
}
public interface EmployeeFactory {
public Employee makeEmployee(EMployeeRecord r) throws InvaliedEmployeeType;
}
public class EmployeeFactoryImpl implements EmployeeFactory {
public Employee makeEmployee(EmployeeRecord r) throws InvaliedEmployeType{
switch (r.type) {
case COMMISSIONED:
return new ComissionedEmployee(r);
case HOURLY:
return new HourlyEmployee(r);
case SALARIED:
return new SalariedEmployee(r);
default:
throw new InvaliedEmployeeType(r.type);
}
}
}
Public class UserValidator {
private Cryptographer cryptographer;
public boolean checkPassword(String userName, String password) {
User user = UserGateway.findByName(userName);
if (user != User.NULL) {
String codedPhrase = user.getPhraseEncodedByPassword();
String phrase = cryptographer.decrypt(codedPhrase, password);
if ("Valid Password".equals(phrase)) {
Session.initialize();
return true;
}
}
return false;
}
}
checkPassword() β checkPasswordAndInitializeSession()
βν κ°μ§βλ§ νλ€λ κ·μΉμ μλ°νμ§λ§, νλ μμ μ λͺ μνλ νΈμ΄ λ μ’λ€.
REAL WORLD CODING
μ μ ν μ£Όμμ κ°λ μ±μ λμ΄κ³ μ½λ©μ νΈλ¦¬νκ²νλ€!