Comparing Ada and Java Alerts
type Priority is (low, medium, hign);
type Alert(tag: priority) is record
time: Time;
cause: String;
case tag is
when low =>
null;
when medium =>
tech: ...
when high =>
engineer: ...
ringAlarmAt: ...
end case;
end record
procedure handle(a: alert) is
begin
log(a.cause);
a.time := current_time;
case a.tag is
when low =>
null;
when medium =>
tech := assign_tech;
when high =>
engineer := assign_eng;
ringAlarmAt := now + delay;
end case;
end handle;
Java:
class Alert{
Time time;
String cause;
void handle(){
log(a.cause);
a.time := current_time;
}
}
class Low extends Alert{
}
class Medium extends Alert{
Person tech;
void handle(){
super.handle();
a.tech = assign_tech();
}
}
class High extends Alert{
Person eng;
Time ringAlarmAt;
void handle(){
super.handle();
a.eng = assign_eng();
ringAlarmAt = current_time + delay;
}
}
Consider: Where is the type definition in each language?
Consider: Where is the code in each language?
Consider: What happens when adding new type/class Emergency in each language?
Consider: What happens when adding new procedure/method doSomething in each language?