(e-mail address removed) wrote:
[...]
Well, then, reflection for bootstrapping is a common
application.
Inasmuch as I think I understand what you mean, I lump this in with
configuration, which I think we have settled of to our mutual
satisfaction. It is a situation where reflective instantiation may
often be useful, but where reflective method invocation is rarely, if
ever, the only viable option.
Once things are rolling, I'm against the use of instanceof.
I am of the same mind, but I don't see how that's germane.
I prefer to program with interfaces and object compostion. The
problem becomes one of assembling a lot of little objects.
Reflection is one way to handle this, so long as the assemblage
takes place infrequently. Jetty uses reflection to basically
build a server from component parts.
Assembling systems from components is great. Programming to interfaces
makes this relatively straightforward, and can also reduce or eliminate
the need to perform reflective method invocations.
Keeping in mind that, if you have a pluggable architecture, and
you want to be acommodating, reflection might worm it's way into
parts of the program. The design pattern is that of the
scriptable component.
Perhaps there's the crux: "want to be acommodating." By that I
interpret you to mean you do not want to demand that plugin components
implement any particular interface or extend any particular class. I
agree that requiring plugins to have some particular class as an
ancestor is inappropriately restrictive, but what's wrong with requiring
a suitable interface to be implemented? If someone is writing a plugin
for your application then it should be very little work to write it to
an API you specify. If someone is adapting an existing component to
your application then it need not be much more (or perhaps any more)
work to write an adapter class than it is to write a suitable
configuration file.
That properties file that says how to instanciate the Foo
plugin, might have also have a few lines on how to make it
frobnicate.
If your application can make use of a library that reflectively performs
generic "doSomething()" operations, then it could just as well make
normal use of reflectively instantiated objects that implement a generic
"SomethingDoer" interface. You have not persuaded me that you _need_ to
use reflection in this case, nor even that it is a significant advantage
to do so.
A JSP page will reflect every time it runs to invoke
the getters and setters on the partipating Beans.
JSP pages do not necessarily reflect when they use beans. Property
names can and should be matched with accessor methods at page
compilation time (via reflection-based Introspection). Even
<jsp:setProperty property="*"> can be compiled such that no reflective
method invocation is required, although perhaps that's a case where the
reflective solution is in fact warranted.
I'm not buying into these distinctions you are making. I don't
see applications as being a programming terminus, where parts of
the Java API off limits because they are too frameworky.
Any body of software will grow until the point where it is
pluggable (and can read e-mail).
You mistake my emphasis. I do not claim that any part of the Java API
is off limits to any application or application type. I claim that
heavy use of reflection is generally a poor design and / or
implementation choice.(*) If you have a body of software that requires
plugability of such magnitude that reflection is the only reasonable
option, then it _is_ an application framework. If you have anything
less, then one of the reasonable non-reflective alternatives is always
better.
* To qualify as making "heavy use of reflection" (according to me), an
application must perform reflective method invocation, not just
reflective instantiation or class introspection.