reflection from a static class?

D

dgront

I have a factory class, say F, that creates object O.

public class O {
public O(P policy);
}

public class F {
public F(Class policyClass);
public O createNew();
}

To create a new object, an instance of a policy class P must be
created before. Each of objects O has its own policy class instance.
Each time method createNew() in factory F is called, it creates a new
instance of P via reflection.

There are several types of policy rules; thus there are several such
classes. It still works, since all of them have similar constructors.
I need however to store somehow parameters related with a policy that
will be used by factory F. They must be known BEFORE factory will
create any object of type P. I can make a static field in each of my
policy class. How can I read the field having Class object?

I wrote the whole story instead of just asking the question because
one can propose a better solution. The limitations are as follows:

- I want to avoid passing an instance of P to the constuctor of my
factory.
- The parameters that F needs are always the same for each created
object O.

Dominik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,097
Latest member
RayE496148
Top