Created
November 27, 2022 04:28
-
-
Save jayhuang75/d2770917bcc46658d43a209dabd8e831 to your computer and use it in GitHub Desktop.
mediator_aircraft.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct PassengerAircraft { | |
id: String, | |
} | |
impl PassengerAircraft { | |
pub fn new(id: impl Into<String>) -> Self { | |
Self { | |
id: id.into(), | |
} | |
} | |
} | |
// A aircraft gets a coornidator(mediator) object by reference. | |
pub trait Aircraft { | |
fn id(&self) -> &str; | |
fn arrive(&mut self, coordinator: &mut dyn Coordinator); | |
fn depart(&mut self, coordinator: &mut dyn Coordinator); | |
} | |
impl Aircraft for PassengerAircraft { | |
fn id(&self) -> &str { | |
&self.id | |
} | |
fn arrive(&mut self, coordinator: &mut dyn Coordinator) { | |
if !coordinator.arrival(&self.id) { | |
return; | |
} | |
} | |
fn depart(&mut self, coordinator: &mut dyn Coordinator) { | |
coordinator.departure(&self.id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment