java/design_pattern
Facade Pattern - 퍼사드 패턴
기계새
2014. 7. 1. 10:16
Facade 패턴
- 코드 랩핑(Code Wrapping)을 통해 의존성을 낮춘다.
- class Hotel {
- // 호텔 정보
- }
- class Flight {
- @SuppressWarnings("unchecked")
- public List<Flight> getFlightsFor(Date from, Date to) {
- return Collections.EMPTY_LIST;
- }
- }
- class HotelBooker {
- @SuppressWarnings("unchecked")
- public List<Hotel> getHotelNamesFor(Date from, Date to) {
- return Collections.EMPTY_LIST;
- }
- }
- class FlightBooker {
- @SuppressWarnings("unchecked")
- public List<Flight> getFlightNamesFor(Date from, Date to) {
- return Collections.EMPTY_LIST;
- }
- }
- class TravelFacade { // 코드 랩핑, 사용자는 Hotel, FLight에 대해 알 필요 없다.
- private HotelBooker hotelBooker;
- private FlightBooker flightBooker;
- public void getFlightAndHotels(Date from, Date to) {
- }
- public HotelBooker getHotelBooker() {
- return hotelBooker;
- }
- public FlightBooker getFlightBooker() {
- return flightBooker;
- }
- }
- public class Ex1 {
- public static void main(String[] args) {
- }
- }