Apologizing for the general headline, I can't think of a way to explain this.
I would like to simulate a scenario in which the system provides funds to users who are associated with policies that apply to requests for these objects.
public interface Facility { public List<Policy> getPolicies(); } public interface Policy { public void apply(Facility facility, Request request); } public interface Request { }
But the request can be reasonable only for a certain type of object, and the policy can really be applied only to the type of object and the type of request specific to this type of object.
public interface Facility<F extends Facility<F>> { public List<Policy<F, ? extends Request<F>>> getPolicies(); } public interface Policy<F extends Facility<F>, R extends Request<F>> { public void apply(F facility, R request); } public interface Request<F extends Facility<F>> { }
But I would also like to be able to specify policies in general so that they can be applied to any Facility supertype.
public interface Facility<F extends Facility<F>> { public List<Policy<? super F, ? extends Request<F>>> getPolicies(); }
But in fact, you only want to request policies that apply to a specific type of request for the object.
public interface Facility<F extends Facility<F>> { public <R extends Request<F>> List<Policy<? super F, R>> getPolicies(); }
My problem is that now I am so confused with all generics, and I canโt even create a policy class that applies to all Equipments that would be something like this if it were legal
public class GeneralPolicy implements Policy<T extends Facility<T>, Request<T>>
How do I make it possible to associate object types, policies, and queries in a way that makes sense as described above? Iโm sure that people will ask for clarification, I have struggled with this for so long that I probably donโt explain anything, or I donโt see the obvious moment at all.