51.
InHouse
Service
Spring Framework
Aspect J
Wicket
Controller
View
DB Access
Business
Requirements
52.
InHouse
Service
Spring Framework
Aspect J
Wicket
Controller
View
DB Access
Business
Requirements
Service レイヤ以降の本来の構成を無視して
テンプレートパターンを適用
InHouse
Service DB Access
Business
Requirements
53.
InHouse
Service
Spring Framework
Aspect J
Wicket
Controller
View
DB Access
Business
Requirements
Service レイヤ以降の本来の構成を無視して
テンプレートパターンを適用
InHouse
Service DB Access
Business
Requirements
Bad!!
54.
InHouse
Service
Spring Framework
Aspect J
Wicket
Controller
View
DB Access
Business
Requirements
Service レイヤ以降の本来の構成を無視して
テンプレートパターンを適用
InHouse
Service DB Access
Business
Requirements
Bad!!
コンポーネントごとの
DI を意識した上で
適切に責務分割を行い
疎な状態を維持する Better
100.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
どうするべきか
101.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
どうするべきか
>> Spring では、HTML や JSP などの他、
レスポンス可能なあらゆるものを
Controller が返却できることを意識する
102.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
より具体的には...
103.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
より具体的には...
>> Spring MVC を採用し、さまざまな View
へ対応可能にしておく。RestController
を使用してフロントを完全分離する (バック
エンドシステムの API 化を促進する)
104.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
@Controller
@RequestMapping("employees")
public class EmployeeController {
@RequestMapping(produces = "text/html")
public String getHtml() { return "employee"; }
@RequestMapping(produces = "application/json", consumes = ..)
@ResponseBody
public String getJson() { return new Employee("Yoichi", "RLS", 30); }
@RequestMapping(produces = "application/xml", consumes = ..)
@ResponseBody
public String getXml() { return new Employee("Yoichi", "RLS", 30); }
}
105.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
@Controller
@RequestMapping("employees")
public class EmployeeController {
@RequestMapping(produces = "text/html")
public String getHtml() { return "employee"; }
@RequestMapping(produces = "application/json", consumes = ..)
@ResponseBody
public String getJson() { return new Employee("Yoichi", "RLS", 30); }
@RequestMapping(produces = "application/xml", consumes = ..)
@ResponseBody
public String getXml() { return new Employee("Yoichi", "RLS", 30); }
}
扱うデータは同じ
106.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
@Controller
@RequestMapping("employees")
public class EmployeeController {
@RequestMapping(produces = "text/html")
public String getHtml() { return "employee"; }
@RequestMapping(produces = "application/json", consumes = ..)
@ResponseBody
public String getJson() { return new Employee("Yoichi", "RLS", 30); }
@RequestMapping(produces = "application/xml", consumes = ..)
@ResponseBody
public String getXml() { return new Employee("Yoichi", "RLS", 30); }
}
扱うデータは同じ
表現の方法が異なる
107.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
どうするべきか
>> Spring では、HTML や JSP などの他、
レスポンス可能なあらゆるものを
Controller が返却できることを意識する
108.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
どうするべきか
>> Spring では、HTML や JSP などの他、
レスポンス可能なあらゆるものを
Controller が返却できることを意識する
>> Spring では、RDB の他、スキーマレス
DB、ファイル、API、などあらゆる外部リ
ソースを永続化レイヤで扱うことを意識する
109.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
より具体的には...
>> Spring MVC を採用し、さまざまな View
へ対応可能にしておく。RestController
を使用してフロントを完全分離する (バック
エンドシステムの API 化を促進する)
110.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
より具体的には...
>> Spring MVC を採用し、さまざまな View
へ対応可能にしておく。RestController
を使用してフロントを完全分離する (バック
エンドシステムの API 化を促進する)
>> Repository レイヤを抽象化してどのよう
な外部リソースへも切替可能にしておく
111.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
public interface EmployeeRepository {
Employee getItem();
}
@Repository @Primary
public class EmployeeJdbcRepository implements EmployeeRepos.. {}
@Repository
public class EmployeeMongoRepository implements EmployeeRep.. {}
@Service
public class EmployeeService {
@Autowired
public EmployeeService(EmployeeRepository employeeRepository) {}
}
112.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
public interface EmployeeRepository {
Employee getItem();
}
@Repository @Primary
public class EmployeeJdbcRepository implements EmployeeRepos.. {}
@Repository
public class EmployeeMongoRepository implements EmployeeRep.. {}
@Service
public class EmployeeService {
@Autowired
public EmployeeService(EmployeeRepository employeeRepository) {}
}
Serviceが見るのは
interface
113.
Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
public interface EmployeeRepository {
Employee getItem();
}
@Repository @Primary
public class EmployeeJdbcRepository implements EmployeeRepos.. {}
@Repository
public class EmployeeMongoRepository implements EmployeeRep.. {}
@Service
public class EmployeeService {
@Autowired
public EmployeeService(EmployeeRepository employeeRepository) {}
}
Serviceが見るのは
interface
Primary 側が DI される
@Bean + @ConditionalOn 等の利用でより柔軟に
114.
集まったバッドノウハウたち
● Spring を使用する上で、
周辺アーキテクチャに縛りを加えてはいけない
● Spring のレイヤデザイン (Controller/Service/
Repository/Template) を無視してはいけない
● 作り方に制限が加わるような
独自の作り込みをおこなってはいけない
115.
Spring のレイヤデザイン (Controller/Service/
Repository/Template) を無視してはいけない
116.
Spring のレイヤデザイン (Controller/Service/
Repository/Template) を無視してはいけない
どうするべきか
117.
Spring のレイヤデザイン (Controller/Service/
Repository/Template) を無視してはいけない
どうするべきか
>> Spring のレイヤデザインに従い、
適切に責務分割を行うことを意識して、
各レイヤが疎な状態を維持できるように
注意して設計・実装を行う
118.
Spring のレイヤデザイン (Controller/Service/
Repository/Template) を無視してはいけない
より具体的には...
Be the first to comment