tyoshikawa1106のブログ

- Force.com Developer Blog -

SFDC:Apexとインターフェイスクラス(interface)のサンプル

Apex開発でインターフェイスクラスを実装するときのサンプルです。インターフェイスクラスは抽象メソッドのみを持つクラスを用意するときに使用します。

Javaのサンプル

Javaの場合は次のように書きます。

package jp.co.bbreak.sokusen._1._8._6;

public interface InterfaceSample {
    abstract String sampleMethod1();
    abstract String sampleMethod2(int num);
}
package jp.co.bbreak.sokusen._1._8._6;

public class ImplementsSample implements InterfaceSample {
    public String sampleMethod1() {
        return "サンプル1";
    }
	
    public String sampleMethod2(int num) {
        return "サンプル2";
    }
}

Apexのサンプル

Apexの場合は次のようになります。interfaceクラスでabstractを宣言する必要はありません。InterfaceSampleRunクラスは実行クラスです。