I am facing a problem quite unique I put you below.
Consider first the following abstract class:
Code:
public abstract class Lattice<E extends Pattern> {
public Lattice () {}
public abstract E meet(E pattern1, E pattern2);
public abstract E join(E pattern1, E pattern2);
public abstract boolean isSubsuming(E pattern1, E pattern2);
public abstract Vector<E> getElements();
public abstract void addElement(E pattern);
}
and the following:
Code:
public abstract class Pattern implements Cloneable
{
public Pattern() {}
public abstract Pattern clone();
}
I use these two classes this way:
Code:
public class IntervalLattice extends Lattice<IntervalPattern> {
Vector<IntervalPattern> elements = new Vector<IntervalPattern> ();
//Here I give an implementation for each abstract method inherited.
public boolean isSubsuming(IntervalPattern pattern1,IntervalPattern pattern2)
//....
}
and
Code:
public class IntervalPattern extends Pattern
{
private double inf;
private double sup;
// Here I give a default constructor, and another to fill the fields
//Then some methods of work not relevant to our problem
}
The problem with that is that I often make as cast
Code:
Lattice<IntervalPattern> l = ...
IntervalLattice il = (IntervalLattice) l;
and this is very bad... not clean, very poorly reusable, and finally not at all generic. In fact, I seek a way of having a single entity and Lattice <E> "ELattice.
I hope I have stated the problem clearly, feel free to say otherwise
Bookmarks