Tuesday, January 26, 2010

Adapter Pattern

Adapter change the interface of a class to make is usable by client. Lets take a real world example....

Railways has got an interface to get the reservation details. Ex




A website which is doing well in ticket booking for flights want to introduce rail ticket booking as well. Since they are in business from long time, they have already got there generic interface in place for flight reservation.



My website TicketReservation class can't talk directly to RailReservation class. To make it happen we need some class which delegates all the calls make to isTicketAvalable to isRailTicketAvailable.



RailTicketAdapter is inherited form the client interface and composing RailTicketReservationImpl.

No comments:

Post a Comment