lundi 23 mai 2016

How to model a query/criteria search for a bookstore repository

I have a book repository/bookstore where clients can search for a book based on author, ISBN, name and lots more. This could potentially lead to numerous find methods in the repository as more fields are added in the future. To solve this, I want to have one find method that takes in a Query object that will encapsulate the search. I also would like to have a QueryBuilder class construct the query. However, I'm having trouble implementing these classes. Any suggestions?? Also as an aside, should pagination support be the concern of the repository or the client constructing the query.

My BookRepository class currently looks like this:

public interface Bookstore {
    Iterable<Book> find(Query query);

    Iterable<Book> find(Query query, int start, int len);

    void add(Book book);

    void remove(Query query);
}

Aucun commentaire:

Enregistrer un commentaire