I want to write the a selector class and have three version of this implementation:
- one with sharing
- one without sharing
- and another one with inherited sharing
I got the design below but I really don't like having to declare the method again and the call the method version in the super class.
Does anybody know how can I achieve the same thing without having the write the methods again in the child classes?
public inherited sharing virtual class ExpensesSelector {
public virtual List<Expense> selectAll() {
return [SELECT Amount, TransactionDate FROM Expense];
}
public with sharing class WithSharingImplementation
extends ExpensesSelector {
public override List<Expense> selectAll() {
return super.selectAll();
}
}
public without sharing class WithoutSharingImplementation
extends ExpensesSelector {
public override List<Expense> selectAll() {
return super.selectAll();
}
}
}