Properties:
- Simply providing a do-nothing implementation of a particular interface.
- Concrete class does nothing, all requests are effectively ignored.
Implementation:
- AbstractOperation declares operations.
- RealOperation implements AbstractOperation and defines operations.
- NullOperation implements AbstractOperation and leaves operations empty.
- Client executes operations on AbstractOperation, does not care about if implemantation is real or null.
Java Standard Library Implementations:
- java.util.Collections#emptyList()
- java.util.Collections#emptyMap()
- java.util.Collections#emptySet()
Example Usage:
@Override
public List<T> findAll(int maxResults) {
if (maxResults == 0)
return Collections.emptyList(); // return empty list
Query query = getSession().createQuery("SELECT p FROM Person p");
return query.setFirstResult(0).setMaxResults(maxResults).list();
}
Comments
Post a Comment