Home
Manage Your Code
Snippet: Interface example (C#)
Title: Interface example Language: C#
Description: Interfaces are designed to manage messaging between objects. When I learned that concept, it made applying them much easier and logical. Somehow, that syntax was the first explaination that really clicked for me. Views: 144
Author: digitalWraith .net Date Added: 4/1/2008
Copy Code  
1Examples:
2
3interface IPlural
4{
5  void Load();
6  void Load(ELoadOptions option, int id);
7}
8
9interface IMembership
10{
11  void Save();
12  void Delete();
13  void Load(int id);
14}
Usage
public class CAddresses : List , IPlural
{
  public void Load()
  {
    // do something
  }
  
  public void Load(ELoadOptions option, int id)
  {
    // do something
  }

}
Notes
Another interesting use for an Interface is an execution handler. IPlural plural = new CAddresses; plural.Load(); // Works; plural.Save(); // Doesn't work because it isn't part of the IPlural interface. I have used this structure to wrap a feature rich object, thereby limited exposure across the boundary.