Created
September 11, 2009 02:49
-
-
Save jbrains/185020 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Controller.initialize() { | |
parachute = Parachute.new(lander) | |
detachment_system = DetachmentSystem.new(parachute) | |
accelerometer = Accelerometer.new() | |
lander = Lander.new(accelerometer, Altimeter.new()) | |
accelerometer.add_observer(detachment_system) | |
} | |
Parachute { | |
needs a lander | |
open() { | |
lander.decelerate() | |
} | |
detach() { | |
if (lander.has_landed == false) | |
raise "You broke the lander, idiot." | |
} | |
} | |
AccelerationObserver is a role { | |
handle_acceleration_report(acceleration) { | |
raise "Subclass responsibility" | |
} | |
} | |
DetachmentSystem acts as AccelerationObserver { | |
needs a parachute | |
handle_acceleration_report(acceleration) {} | |
if (acceleration <= -50.ms2) { | |
parachute.detach() | |
} | |
} | |
} | |
Accelerometer acts as Observable { | |
manages many acceleration_observers | |
report_acceleration(acceleration) { | |
acceleration_observers.each() { | |
each.handle_acceleration_report(acceleration) | |
} | |
} | |
} | |
Lander { | |
needs an accelerometer | |
needs an altimeter | |
decelerate() { | |
// I know how much to decelerate by | |
accelerometer.report_acceleration(how_much) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment