![]() |
![]() |
![]() |
*> 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.
インターフェイスのサンプルも参照してください。このサンプルは、Start > All Programs > Micro Focus Enterprise Developer > Samples > Visual COBOL Samples, under COBOL for .NET. に用意されています。
インターフェイスは、実装なしで名前およびシグネチャを指定するインスタンス メソッドのリストです。
プログラムで特定のインターフェイスの実装を宣言すると、そのインターフェイス内に定義されたすべてのメソッドの実装がプログラムで必要になります。インターフェイスを実装するには、クラス定義で OBJECT 句の IMPLEMENTS 指定を使用して、指定したインターフェイスの実装をプログラムが提供するように宣言します。また、このインターフェイス型へのオブジェクト参照も宣言できます。