• Post Reply Bookmark Topic Watch Topic
  • New Topic

Replacing class at runime with modified code  RSS feed

 
Amol Sonawane
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code snippet from my my client code:
Test object = new Test().

I have a proxy "Test" class that has exactly same methods as that of "Test" class . Now When someone creates instance of Test, I would like to intercept that call
and return the instance of My "TestProxy" instead of orginal "Test" class. I need to add new behavior at runtime by using this modified version of Test (proxy class).
How can I do that without changing client code?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not used it but people say that AOP(Aspect Oriented Programming) intends to do this for you.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using AOP you can influence code without touching it, but I don't think it can effect changes that aren't fixed at compile time.

I don't see how this could be done if the client code does an actual "new Test()"; it would be feasible if the client code uses a proxy or factory approach.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!