Reference‎ > ‎

Inheritance

As of version 2.2.0, it is now possible to use inheritance, both in the persistent objects, and in the logic classes.

Inheritance in persistent objects

Hibernate has a comprehensive mechanism for handling inheritance. We refer you to the Hibernate documentation for the various options. All inheritance configurations should work with ABL, though they have not all been tested (there are just too many combinations).

Inheritance in logic objects

It is now possible to use inheritance in logic classes. For instance, assuming that you have a persistent object called Customer, and a subclass called SpecialCustomer, you could define a logic class CustomerLogic:

public class CustomerLogic {

@CurrentBean
private Customer customer;
@OldBean
public Customer oldCustomer;
@Constraint
public void constraintCreditLimit() {
        // Do something here
    }

@Sum("purchaseOrders.amountTotal where paid = false")
public void deriveBalance() { }
@Count("purchaseOrders")
public void deriveNumOrders() { }
}

with a subclass SpecialCustomerLogic:

public class SpecialCustomerLogic extends CustomerLogic {

@CurrentBean
private SpecialCustomer customer;

@Override
@Constraint
public void constraintCreditLimit() {
        // Do something here
        }

@Constraint
public void constraintAge() {
        // Do something here
        }

        @Override
@Sum("purchaseOrders.amountTotal where paid = false and ready = true")
public void deriveBalance() { }
}

A few items to notice:
  • it is possible, but of course not required, to override the CurrentBean, OldBean and LogicContextObject variables, though it usually doesn't make sense to do it for LogicContextObject (it's easier to simply inherit it if it's already defined in a superclass). Overriding CurrentBean and OldBean can avoid some unsightly casts.
  • it is possible to override logic methods, such as formulas, constraints, etc...
  • obviously, all the limits and requirements of Java inheritance apply.

Comments