IntermediateLesson 21 of 37
Apex classes and object-oriented code
Classes, interfaces, inheritance and sharing.
apex
public with sharing class PricingService {
private static final Decimal TAX = 0.2;
public Decimal withTax(Decimal net) {
return net * (1 + TAX);
}
}
public interface Notifier { void send(String msg); }
public virtual class BaseNotifier implements Notifier {
public virtual void send(String msg) { System.debug(msg); }
}- Access modifiers:
private,protected,public,global. with sharingmakes the class respect the running user's record access (use it by default);without sharingignores sharing;inherited sharingfollows the caller.- Use custom exceptions (
public class MyException extends Exception {}),Custom Metadata TypesandCustom Settingsfor configuration.