0

Can i use Byte Buddy to enhance a class at runtime by inheriting from an abstract class?

@AggregateRoot
public class Organization {
}

I should be able to intercept all instances of Organization and enhance it by inheriting from an abstract class like below.

public abstract class BaseAggregateRoot {
  public void notify() {
    //Notify domain events
  }
}
Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
FFL
  • 669
  • 7
  • 22

1 Answers1

0

So what you want to do is to dynamically change the super class of a given class at runtime? Currently, this is not possible in Byte Buddy. Instead, you can add interfaces with default methods defined, when you are using Java 8. Would that be an option?

What you can also do is to subclass the BaseAggregateRoot class at runtime, name the class Organization and add the annotation on top of it.

I will however consider this as a future feature for Byte Buddy.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192