SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Flight {
  2.  
  3. }
  4.  
  5. class Observer {
  6.     private String eMail;
  7.     private Flight flight;
  8.  
  9.     Observer(String eMail, Flight flight) {
  10.         this.eMail = eMail;
  11.         this.flight = flight;
  12.     }
  13.  
  14.     public void subscribe() {
  15.         System.out.println("Subscribe this flight on this eMail");
  16.     }
  17.  
  18. }
  19.  
  20. class Observable {
  21.  
  22.     private ArrayList<Observer> observers = new ArrayList<>();
  23.  
  24.     public void addObserver(Observer o) {
  25.         observers.add(o);
  26.     }
  27.  
  28.     public void removeObserverByFlight(Flight f) {
  29.         observers.remove(f);
  30.     }
  31.  
  32.     public void sendMessageByFlight(Flight flight) {
  33.         System.out.println("Your flight is available");
  34.     }
  35. }
  36.  
  37. class ClientController {
  38.  
  39.     Observable observable;
  40.  
  41.     public void orderFlight(Flight flight, String email) {
  42.  
  43.         try {
  44.             //flight is reserved
  45.         } catch (Exception noPlaces) {
  46.             Observer observer = new Observer(email, flight);
  47.             observable.addObserver(observer);
  48.             observer.subscribe();
  49.         }
  50.     }
  51.  
  52. }
  53.  
  54. class FlightRepository implements Repository<Flight> {
  55.  
  56.     Observable observable = new Observable();
  57.    
  58.    
  59.     @Override
  60.     public void add(Flight flight) {
  61.         //add flight
  62.         observable.sendMessageByFlight(flight);
  63.         observable.removeObserverByFlight(flight);
  64.     }
  65.  
  66.     @Override
  67.     public void remove(Flight flight) {
  68.  
  69.     }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top