How to add dynamic behaviour inside java classes