The problem you face here is that you want to abstract over two informationen a kind of common "expiration" information. The problem is that this abstraction is unknown to the code, it's currently only in present in your head :)
It's currently implemented in 2 flavours: Integers and Dates (though I have no idea what this Integer is about? Is it a year count? ... the number of lottory winner since 1990? I don't know).
I would propose adding a new Interface
for this abstraction, e.g.
public interface Expiration<T> {
T getExpiration();
}
In this case your two base classes can implement Expiration<Date>
and Expiration<Integer>
and you could base your validation logic on that. For example like:
public boolean isValid(Expiration<Date> potentialyExpired) {
final Date expirationDate = potentialyExpired.getExpiration();
final Date now = new Date();
return expirationDate.before(now);
}
That can only be done when you can access the classes in question though. Is this abstraction enough or are you in need in even more?
You could want to abstract over the different type of Expiration
in such a way that you don't need to have both of them around and unify them at some point. But to decide that kind of thing one would need to know more about the meaning of the other type (the Integer
one).