Tutorial

Introduction

Reflexive aims to simplify refactoring by removing string literals when addressing properties or methods. By dynamicaly retrieving the property or method by invoking the getter or method, we make refactoring safer since there is compile time checking.

Step 1: Creating the control object

Reflexive uses a control object, which is from the same class as your javabean. For the sake of this tutorial, we have a customer class with some common properties.

Customer customer = Reflexive.create( Customer.class );

Keep in mind that, although it's a customer object, the customer is not intented to be used in any other way then invoking getters. Doing so will result in runtime errors.

Step 2: Using the control object

Resolving properties on the control object is now very easy. Just invoke any getter your javabean and let Reflexive resolve the property.

 String property = Reflexive.resolvePropertyName( customer.getName() );

This will return the string "name". You can now use this string where you would normally hardcode it. For instance when dynamicly resolving properties by reflection, making Hibernate queries, etc.

 String property = Reflexive.resolveNestedPropertyName( customer.getAddress().getCity().getName() );

This call statement returns "address.city.name". Notice that you only need to create 1 control object to resolve nested properties!