David King, Software Developer and Enthusiast

Dynamic Method Invocation – Java Reflection

This code is the beginning of a basic CRUD pattern implementation, where the POJO (User) has a handler (UserHandler) that processes the required business logic related to the POJO. The basic type is the interface DynamicMethodInvoker that accepts a type T that is the return type for the method invocation. The default implementation of the DynamicMethodInvoker is the abstract class AbstractDynamicMethodInvoker. The handler (UserHandler) will subclass the AbstractDynamicMethodInvoker and implement an interface named CrudProcessor. CrudProcessor accepts two generic types, that is T, representing the POJO and R, representing the return type for the create, update and delete methods. The code follows: