템플릿 메서드(Template Method) 패턴
public class DbAthenticator {
private UserDao userDao;
public DbAthenticator(UserDao userDao) {
this.userDao = userDao;
}
public Auth authenticate(String id, String pw) throws Exception {
User user = userDao.selectById(id);
boolean auth = user.equalPassword(pw);
if(!auth) {
throw new Exception("has not auth");
}
return new Auth(id, pw);
}
}
상위 객체가 흐름 제어 주체
템플릿 메서드와 전략 패턴의 조합
Last updated