• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Override object method at runtime

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an object retrived from the factory method of a thirdparty library and I want to override a method on this object.

Please clarify How best I can do this.

Thanks & Regards
Eshwar.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eswar Rao wrote:I have an object retrived from the factory method of a thirdparty library and I want to override a method on this object.
Please clarify How best I can do this.


If it implements an interface (as most factory objects do), write a wrapper class that implements the same interface, and:
1. Implement your own version of the particular method.
2. Implement the rest of the methods as forwarders.
You might want to look at the Decorator Pattern for more info.

If it doesn't, you have more of a problem.

Winston
 
Rancher
Posts: 1043
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If there are many methods, you can even consider using a Dynamic Proxy to implement the above idea.

http://docs.oracle.com/javase/1.4.2/docs/guide/reflection/proxy.html

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic