mercredi 7 octobre 2015

Wrapping Dao in the class implementing more convinient interface

The question is about design in Java.

I have a java.util.date object, e.g. '2015-10-10' and I have an entity called Player representing by the class:

public class Player{
    //impl
}

Now, I need to provide a transparent way for getting Collection<Player> by different restrictions. For instance, it's also possible to restrict Players by their amount, registration date, account update date by applying different operators to them like (<, >, !=, < & > i.e. between, etc).

Since the set of such operators is the thing to change in the future, I tend to wrap the object retrieving into the Function interface.

But currently all Players are in a DataBase and the actual retrieving is performed by calling to a DAO method. And this's what I'm confused by.

In my case a Function<T, V> implementation would look like:

public class RegistrationDateLessThanFunctionImpl implements Function<Date, Collection<Player>>{
    private PlayerDao playerDao;
    //GET, SET

    public Collection<Player> apply(Date d){
        return playerDao.getPlayersByRegistrationDateLessThan(d);
    }
}

Question: Is it correct to wrap DAOs into such interfaces, so the clients are not aware of using DAO at all. They just use a function, mapping values into a set of Players.

I couldn't answer this from the Official documentation.

Aucun commentaire:

Enregistrer un commentaire