// Interface definition
interface IClock
{
int Hour { get; }
int Minute { get; }
void Reset();
}
// Extending an interface
interface IAlarmClock : IClock
{
int AlarmHour { get; set; }
int AlarmMinute { get; set; }
void Snooze(int time);
}
// Interface implementation
class WristWatch : IAlarmClock, System.IDisposable
{
public int Hour { get; set; }
public int Minute { get; set; }
public int AlarmHour { get; set; }
public int AlarmMinute { get; set; }
public void Dispose()
{
Reset();
}
public void Reset()
{
Hour = 0;
Minute = 0;
AlarmHour = 0;
AlarmMinute = 0;
}
public void Snooze(int time)
{
AlarmMinute += time;
}
}
|
*> Interface definition
interface-id IClock
01 Hour binary-long property with no set.
01 Minute binary-long property with no set.
method-id Reset.
end method.
end interface.
*> Extending an interface
interface-id IAlarmClock implements type IClock.
01 AlarmHour binary-long property.
01 AlarmMinute binary-long property.
method-id Snooze (#time as binary-long).
end method.
end interface.
*> Interface implementation
class-id WristWatch implements type IAlarmClock,
type System.IDisposable.
working-storage section.
01 Hour binary-long property with no set.
01 Minute binary-long property with no set.
01 AlarmHour binary-long property.
01 AlarmMinute binary-long property.
method-id Dispose.
invoke self::Reset()
end method.
method-id Reset.
set Hour to 0
set Minute to 0
set AlarmHour to 0
set AlarmMinute to 0
end method.
method-id Snooze (#time as binary-long).
add #time to AlarmMinute
end method.
end class.
|
' Interface definition
Interface IClock
ReadOnly Property Hour As Integer
ReadOnly Property Minute As Integer
Sub Reset()
End Interface
' Extending an interface
Interface IAlarmClock
Inherits IClock
Property AlarmHour As Integer
Property AlarmMinute As Integer
Sub Snooze(time As Integer)
End Interface
' Interface implementation
Class WristWatch
Implements IAlarmClock, IDisposable
public Property Hour As Integer Implements IClock.Hour
public Property Minute As Integer Implements IClock.Minute
public Property AlarmHour As Integer Implements IAlarmClock.AlarmHour
public Property AlarmMinute As Integer Implements IAlarmClock.AlarmMinute
Public Sub Dispose() Implements IDisposable.Dispose
Reset()
End Sub
Public Sub Reset() Implements IClock.Reset
Hour = 0
Minute = 0
AlarmHour = 0
AlarmMinute = 0
End Sub
Public Sub Snooze(time As Integer) Implements IAlarmClock.Snooze
AlarmMinute = AlarmMinute + time
End Sub
End Class
|