Book Image

Learning Apex Programming

5 (1)
Book Image

Learning Apex Programming

5 (1)

Overview of this book

Table of Contents (17 chapters)
Learning Apex Programming
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

The Pablo Picasso of Apex


In addition to the built-in interfaces we have looked at so far, Apex also includes the ability to create and implement your own interfaces. When you define an interface in Apex, you only supply the methods names and signatures, not the inner logic. This feature allows you to design high-level processes that can be implemented in multiple ways. To define an interface, you replace the word class in the definition with the word interface. The following code block defines an interface and then later implements it twice:

public interface myInterface {

  String compileString();
  Integer calculateNumber();

}

public class budgetClass implements myInterface{
  public String compileString(){
    return 'Our budget is ';
  }
  public Integer calculateNumber(){
    return 1000;
  }
}

public class profitClass implements myInterface{
  public String compileString(){
    return 'Our profit is ';
  }
  public Integer calculateNumber(){
    return 500;
  }
}

Interfaces aren...