Amazon Interview Question
Software Engineer / DevelopersTeam: video
Country: United Kingdom
Interview Type: Phone Interview
Ya, fundementally using 'Mediator' pattern i guess. Three fundemental objects i see are 'Aircraft' and 'ATS Controller' and 'Common Resources'. 'Aircraft' basically seeks permissions for various stages and Controller fundementaly validates and grants. In the process of validation, controller communicates with other 'Aircraft' objects and interacts with 'common resources'
Various operations/member functions across these classes could be as follows :
Aircraft :
-pre-flight activities
- take-off
-inFlight
- descent
-landing
Note - Every stage is time-bound, sending/receiving grants based on start/end times.
Controller/base
- Weather report engine (common for location)
-Grant pre-flight
-grant take-off
-Monitor inFlight route
- Monitor Arrivals, departures, transits
- Two-way Communication with Controllers at other locations
- Provide Alerts (categorized based on severity)
- Address emergenies ( Ex- Engage rescue flights when needed etc)
- Constantly poll all aircrafts in jurisdiction.
Note - Controller class can internally use 'descision trees' to 'Grant' a given permission based on interaction with other Aircraft objects and resources.
Also for basic departure and arrival grants, a priority queue could be maintained. Priority could be defined based on how close aircraft is to the base, fuel-level, Number of passengers, etc
Common Resources:
-Runways availability/condition
- Engineering staff
- Flight safety crew
ATS system as such is mission-critical and should be extremely fault-tolerant and with Zero down-time. To meet these goals, reduncancies could be present for 'Controller' objects (say primary, secondary controllers) which ensure to give grants/alerts . Also Controllers should continously 'Poll' the black-boxes (think of them as connected IPs) for constant 'in-touch' situation.
Please let me know your opinion on this design.
I found the solution on a paper named design of a air traffic control system using UML .As I am unable to post the link here, if you are interested in solution please search for "DESIGN OF FORMAL AIR TRAFFIC CONTROL SYSTEM THROUGH UML"
Not sure if I was expected to do most of these in the 45 minutes slot
package com.javapapers.designpattern.mediator;
public class ATCMediator implements IATCMediator {
private Flight flight;
private Runway runway;
public boolean land;
public void registerRunway(Runway runway) {
this.runway = runway;
}
public void registerFlight(Flight flight) {
this.flight = flight;
}
public boolean isLandingOk() {
return land;
}
@Override
public void setLandingStatus(boolean status) {
land = status;
}
}
package com.javapapers.designpattern.mediator;
public interface Command {
void land();
}
package com.javapapers.designpattern.mediator;
public interface IATCMediator {
public void registerRunway(Runway runway);
public void registerFlight(Flight flight);
public boolean isLandingOk();
public void setLandingStatus(boolean status);
}
package com.javapapers.designpattern.mediator;
public class Flight implements Command {
private IATCMediator atcMediator;
public Flight(IATCMediator atcMediator) {
this.atcMediator = atcMediator;
}
public void land() {
if (atcMediator.isLandingOk()) {
System.out.println("Landing done....");
atcMediator.setLandingStatus(true);
} else
System.out.println("Will wait to land....");
}
public void getReady() {
System.out.println("Getting ready...");
}
}
package com.javapapers.designpattern.mediator;
public class Runway implements Command {
private IATCMediator atcMediator;
public Runway(IATCMediator atcMediator) {
this.atcMediator = atcMediator;
atcMediator.setLandingStatus(true);
}
@Override
public void land() {
System.out.println("Landing permission granted...");
atcMediator.setLandingStatus(true);
}
}
package com.javapapers.designpattern.mediator;
public class MediatorDesignPattern {
public static void main(String args[]) {
IATCMediator atcMediator = new ATCMediator();
Flight sparrow101 = new Flight(atcMediator);
Runway mainRunway = new Runway(atcMediator);
atcMediator.registerFlight(sparrow101);
atcMediator.registerRunway(mainRunway);
sparrow101.getReady();
mainRunway.land();
sparrow101.land();
}
}
air traffic control system is a classic example of mediator design pattern.
- king July 11, 20131) Define an interface for mediator.
2) Define another interface for client.
3) Define concrete impl for the mediator interface
4) Define concrete impl for the flight interface.
Each flight object needs to register with the mediator.