Thursday, April 10, 2014

What is interface in Apex and how to create interface in apex?

What is interface in Apex and how to create interface in apex?


An interface is like a class in which none of the methods have been implemented the method signatures are there, but the body of each method is empty. To use an interface, another class must implement it by providing a body for all of the methods contained in the interface.

Defining an interface is similar to defining a new class.For example, a company might have two types of purchase orders, ones that come from customers, and others that come from their employees. Both are a type of purchase order. Suppose you needed a method to provide a discount. The amount of the discount can depend on the type of purchase order.

An interface can extend another interface. As with classes, when an interface extends another interface, all the methods and properties of the extended interface are available to the extending interface

Interface:
public interface PurchaseOrder {
// All other functionality excluded
Double discount();
}



Implemented Class:

// One implementation of the interface for customers
public virtual class CustomerPurchaseOrder implements PurchaseOrder {
public virtual Double discount() {
return .05; // Flat 5% discount
}
}








1 comments:

nick jones said...


thanks for sharing..
Server and Storage

Post a Comment

 
| ,