Reflective discovery of an inner class in an API

Posted by wassup on Programmers See other posts from Programmers or by wassup
Published on 2014-08-16T09:47:08Z Indexed on 2014/08/21 22:26 UTC
Read the original article Hit count: 256

Filed under:
|

Let me ask you, as this bothers me for quite a while but appears to be subjectively the best solution for my problem, if reflective discovery of an inner class for API purposes is that bad idea?

First, let me explain what I mean by saying "reflective discovery" and all that stuff.

I am sketching an API for a Java database system, that'll be centered around block-based entities (don't ask me what that means - that's a long story), and those entities can be read and returned to the Java code as objects subclassed from the Entity class.

I have an Entity.Factory class, that, by means of fluent interfaces, takes a Class<? extends Entity> argument and then, uses an instance of Section.Builder, Property.Builder, or whatever builder the entity has, to put it into the back-end storage.

The idea about registering all entity types and their builders just doesn't appeal to me, so I thought that the closest solution to the problem that'd suffice my design needs would be to discover, using reflection, all inner classes of Entity classes and find one that's called Builder.

Looking for some expert insight :) And if I missed some important design details (which could happen as I tried to make this question as concise as possible), just tell me and I'll add them.

© Programmers or respective owner

Related posts about java

Related posts about api