Announcement Announcement Module
No announcement yet.
Accessing contructors and static methods through interfaces Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing contructors and static methods through interfaces

    I gave some thought, a while back, to managing the static elements of dynamically loaded classes, by which I mean static methods and constructors.

    It seems to me that a major reason for the popularity of beans is that it's messy to access these things by reflection.

    I came up, and played with a possible approach, and it seems to me that this makes more sense in the Spring evironment and might fit the model quite well.

    What I've written is a factory object which is associated with an interface. You pass a Class to this factory and it returns a Proxy object, implementing the interface by mapping interface methods to constructors and static methods of the class. The two are distinguished by a @Constructor annotation. Any mismatch causes and exception when the proxy is created, therafter all the exception handling etc. behaves normally.

    What this would allow is the use of static elements in a decoupled kind of way. The interface specifies a contract with the Class in the same way that a regular interface specifies a contract with instances of the class.

    Do people think this might be a useful addition to Spring?