Click here to Skip to main content
15,914,013 members
Home / Discussions / C#
   

C#

 
Generalxml in windows forms Pin
rasarit1713-Feb-04 8:43
rasarit1713-Feb-04 8:43 
GeneralRe: xml in windows forms Pin
Heath Stewart13-Feb-04 12:36
protectorHeath Stewart13-Feb-04 12:36 
GeneralItembackground Color in ListBox Pin
Snowjim13-Feb-04 8:01
Snowjim13-Feb-04 8:01 
GeneralRe: Itembackground Color in ListBox Pin
Heath Stewart13-Feb-04 12:32
protectorHeath Stewart13-Feb-04 12:32 
GeneralRe: Itembackground Color in ListBox Pin
Snowjim13-Feb-04 14:27
Snowjim13-Feb-04 14:27 
GeneralRe: Itembackground Color in ListBox Pin
Heath Stewart13-Feb-04 16:48
protectorHeath Stewart13-Feb-04 16:48 
GeneralInterfaces Pin
MrJJKoolJ13-Feb-04 7:21
MrJJKoolJ13-Feb-04 7:21 
GeneralRe: Interfaces Pin
Heath Stewart13-Feb-04 12:29
protectorHeath Stewart13-Feb-04 12:29 
Interfaces are contracts. They define methods, properties, and events that a class must implement in order for callers to use certain features. Classes can only extend one class in .NET, but structs and classes can implement as many interfaces as you want.

Take IList for example. Since it inherits form ICollection and IEnumerable, this means that any class that implements IList is enumerable and has methods and properties that let you add, remove, and index items, as well as clear them. This fosters a good OO design because a caller doesn't have to know the exact Type of an object to use its methods.

For instance, the DataGrid.DataSource accepts an Object. Internally, it checks if this object supports IList or IListSource. It doesn't care if it is a DataSet, an array, or any collection. Just that it supports one of those two interfaces.

This is very handy for creating abstract implementations like plug-ins. You don't need to know a specific Type at design-time or run-time, just that it suports a particular interface. Lets say an application that can uses plug-ins reads a list of Types from the configuration file and defines an interface like so:
public interface IPlugin
{
  void Initialize(Control parent);
  string Caption { get; }
}
Then when the applications get each type, it can do something like this:
IPlugin plugin = (IPlugin)Activator.CreateInstance("some type");
plugin.Initialize(this);
It doesn't need to know the Type, just that the Type implements the interface (you should catch exceptions though, in case the cast fails).

For more information about plug-ins, which are a good example of interfaces, try searching[^] CodeProject.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Interfaces Pin
MrJJKoolJ13-Feb-04 12:34
MrJJKoolJ13-Feb-04 12:34 
GeneralImplementing IDropTargetInterFace in C# Pin
vnutheti13-Feb-04 6:35
vnutheti13-Feb-04 6:35 
GeneralRe: Implementing IDropTargetInterFace in C# Pin
Heath Stewart13-Feb-04 12:20
protectorHeath Stewart13-Feb-04 12:20 
GeneralRe: Implementing IDropTargetInterFace in C# Pin
vnutheti13-Feb-04 13:44
vnutheti13-Feb-04 13:44 
GeneralRe: Implementing IDropTargetInterFace in C# Pin
Heath Stewart13-Feb-04 16:46
protectorHeath Stewart13-Feb-04 16:46 
GeneralRe: Implementing IDropTargetInterFace in C# Pin
vnutheti14-Feb-04 8:06
vnutheti14-Feb-04 8:06 
GeneralUsing and intercepting command line programs Pin
noahfields13-Feb-04 6:00
noahfields13-Feb-04 6:00 
GeneralRe: Using and intercepting command line programs Pin
Kentamanos13-Feb-04 7:12
Kentamanos13-Feb-04 7:12 
GeneralRe: Using and intercepting command line programs Pin
noahfields14-Feb-04 4:05
noahfields14-Feb-04 4:05 
GeneralDataset and Recordset Pin
ASGill13-Feb-04 5:11
ASGill13-Feb-04 5:11 
GeneralRe: Dataset and Recordset Pin
Heath Stewart13-Feb-04 5:28
protectorHeath Stewart13-Feb-04 5:28 
GeneralControlling Panels via RadioButtons Pin
srt713-Feb-04 4:47
srt713-Feb-04 4:47 
GeneralRe: Controlling Panels via RadioButtons Pin
Heath Stewart13-Feb-04 5:32
protectorHeath Stewart13-Feb-04 5:32 
Generaldocked controls snapping to grid in compiled app Pin
Nathan Ridley13-Feb-04 4:16
Nathan Ridley13-Feb-04 4:16 
GeneralRe: docked controls snapping to grid in compiled app Pin
leppie13-Feb-04 19:14
leppie13-Feb-04 19:14 
GeneralRe: docked controls snapping to grid in compiled app Pin
Nathan Ridley14-Feb-04 0:06
Nathan Ridley14-Feb-04 0:06 
AnswerRe: listView - is there a bug? Pin
thomasa13-Feb-04 1:54
thomasa13-Feb-04 1:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.