Real Time Scenario For Abstract Class and Interface: Industry Oriented Java-1
Real Time Scenario For Abstract Class and Interface: Industry Oriented Java-1
• We have a class Animal that has a method sound() and the subclasses of it
like Dog, Lion, Horse, Cat etc.
• Since the animal sound differs from one animal to another, there is no point to
implement this method in parent class.
• This is because every child class must override this method to give its own
implementation details, like Lion class will say “Roar” in this method
and Dog class will say “Woof”.
Real Problem Scenario
• Lets keep our service as simple as, Displaying flights available from
vendors like "airasia", "british airways" and "emirates".
• Place and order for seat to respective vendor.
How should we design our application considering interfaces and abstract class? In this
scenario, interface is useful or abstract class?
We are just a middle man/aggregator and our task is to first enquire "airasia", then enquire
"british airways" and at last enquire "emirates" about the list of flights available and later if
customer opts for booking then inform the respective flight vendor to do booking.
Hint
interface FlightOpeartions{
void getAllAvailableFlights();
void booking(BookingObject bookingObj);
}
class BookingObject{}
Solution Scenario(Contd..)
class BritishAirways implements FlightOpeartions{