What is a control?

time to read 3 min | 457 words

I had an argument yesterday about the interface that a control should expose to the prorammer, and I think that it makes for an interesting discussion.

First, we are not talking about a System.Web.UI.Control, which is used to display a list of possible organization units. This control is written spesifically for this purpose.

My take on the interface is something like this:

public class OuPager : Control
{
  public OrganizationUnit CurrentOrganizationUnit { get; set; }
  public event EventHandler OrganizationUnitChanged;
}

The other approach is to make the control responsible for displaying the organization unit only, and then the interface looks like:

public class OuPager : Control
{
  public void SetCurrentOrganizationUnit(OrganizationUnit current);
  public event EventHandler PressedNext;
  public event EventHandler PressedPrev;
  public bool HasNext { set; }
  public bool HasPrev { set; }
}

In my opinion, putting the control in charge of the data access and manipulating the list of items free the developer that uses this control from worrying about a lot stuff.

The other opinion is that this is a UI control and it shouldn't do anything beyond what I explicitly tell it to do.

Comments?

Just to clarify: Here is what I mean by "data access" in the control:

this.DataSource = Repository<OrganizationUnit>.FindAll();