开发者

Why use default access for methods in a generic DAO interface?

I found this code for a generic DAO interface while browsing around:

public interface GenericDAO<T, ID extends Serializable> {

    Class<T> getEntityClass();

    T findById(final ID id);

    List<T> findAll();
    List&开发者_StackOverflowlt;T> findByExample(final T exampleInstance);

    List<T> findByNamedQuery(
        final String queryName,
        Object... params
    );

    List<T> findByNamedQueryAndNamedParams(
        final String queryName,
        final Map<String, ?extends Object> params
    );

    int countAll();

    int countByExample(final T exampleInstance);

    T save(final T entity);

    boolean delete(final T entity);
}

Is there any reason in particular for leaving methods with the default access modifier (class/package: yes, subclass/world: no)?

P.S: An added question. Are IDs usually found in implementations which don't depend on a RDBMS (XML, flat file...) ?


Methods of an interface are implicitely public. Using the public modifier is thus redundant and unnecessary.

Checkstyle even has a rule to check that public is not used in interface methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜