I am thinking if is there some design pattern to work with objects and its states. In my REST API I have a access token objects, these objects contain information about authenticated clients:
public class AccessToken {
private final String accessToken;
private DateTime expiration;
private DateTime created;
}
but this AccessToken has an expiration time. When I check, whether client is logged in (= token exists), I would like to check whether token is not expired.
Question
Should be this method - e.g. .isValid()
, .isExpired()
for better clarity and simplicity be in AccessToken
class or should I have another class that will do a validation?