Hi Kevin,
In addition to Bonnie's excellent info, we have to create questionnaires that require iteration of various controls on forms and execution certain methods and/or access certain properties that some but not all controls may have. With controls developed to an interface it's really to use contructs like:
If (MyControl is MyControlInterface1)
{
MyControl.MyMethod();
MyControl.MyProp = ...
}
Bill
>I understand that an interface forces a class to use a defined set of properties and methods.
>
>In the code below, why use the interface? This seems to me to limit the programmer
>who inherits from this class by forcing him/her to add code to their class that they
>may not use. Why not just allow the programmer to implement the class any way they want.
>
>Can someone provide a more concrete purpose for an Interface? I'm guessing that I don't
>full understand.
>
>Thanks
>
>
>
>using System;
>using System.Collections.Generic;
>using System.Text;
>
>namespace Interface1
>{
> interface IMessage
> {
> // Send the message. Returns True if success, False otherwise
> bool Send();
>
> // The message to send
> string Message { get; set; }
>
> // The address to send to
> string Address { get; set; }
>
> }
>
> public class EmailMessage : IMessage
> {
> string _address = "";
> string _message = "";
>
> public bool Send()
> {
> bool bRetVal = false;
> return bRetVal;
> }
>
> public string Message
> {
> get
> {
> return _message;
> }
> set
> {
> _message = value;
> }
> }
>
> public string Address
> {
> get
> {
> return _address;
> }
> set
> {
> _address = value;
> }
> }
>
> }
>}
>
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.