Domain Object List

Simple AdapterInterface to encapsulate functionality performed on a list. In just about any program, you will end up with list of objects that you will need to attach behavior to. Typical operations include sorting, filtering, and searching. Often, people implement the behavior by creating static utility methods or just writing the method where needed. However, the same functionality is often needed in several areas of the code, so the same methods are duplicated or refactored into ugly static utility methods. Also, the list itself is often passed around and modified, so you have no real control over access.

DomainObjectList solves this problem by wrapping the list or collection with a domain specific interface. On a superficial level, the interface provides type safety to the list. More importantly, it provides a single reusable interface for list functionality.

 public class LineItemList?{
  private final List _items = new ArrayList();

public void add(LineItem? item){ _items.add(item); }

public LineItemList? findOpenItems(){ LineItemList? newList = new LineItemList?(); Iterator iter = _items.iterator(); while(iter.hasNext()){ LineItem? nextItem = (LineItem?)iter.next(); if(nextItem.isOpen()) newList.add(nextItem); } return newList; } }
-- MikeRettig


See also StronglyTypedCollection


EditText of this page (last edited March 20, 2010) or FindPage with title or text search