Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Created November 27, 2022 04:28
Show Gist options
  • Save jayhuang75/d2770917bcc46658d43a209dabd8e831 to your computer and use it in GitHub Desktop.
Save jayhuang75/d2770917bcc46658d43a209dabd8e831 to your computer and use it in GitHub Desktop.
mediator_aircraft.rs
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