2

In case of customize object behavior at runtime, Java seems to provide two solutions, Java Scripting and Dynamic Proxy.

suppose I have a configuration file and an interface I in Java, I can either create and load class implementing I according to configuration or I can use dynamic proxy to make implementation of the I as well. Both technique is a little advanced. I am now wondering

1- which of these two ways is more efficient in development? 2- which of these technology is more optimized in performance? 3- which way is more maintainable? (before product is stable, configuration might be changed frequently)

Sincerely

Korben
  • 734
  • 1
  • 7
  • 26

1 Answers1

0

I think the first technique is the most widely used one. I have never used dynamic proxy to be honest, but coding against an interface and then determining the concrete type based on configuration is simply the inversion of control concept (or dependency injection) which is used in Spring and adopted by many other frameworks as well.

Community
  • 1
  • 1
Rami
  • 7,162
  • 1
  • 22
  • 19
  • Thanks, it seems IOC frameworks like Spring is a better choice then Dynamic Proxy, but Framework is not an option for me for two reasons. first is I have never used Spring and it takes time to learn and design system using it and I want to keep project as small in size as possible. – Korben Jun 26 '15 at 02:04
  • @Korben, you can still implement the same concept from scratch on a smaller scale as you said in your question. Simply adopt the object oriented concept of always coding against an interface and then determine the concrete implementation classes at run time through configuration. This will just works! :) – Rami Jun 26 '15 at 06:36