Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why Use Interfaces
Message
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Titre:
Why Use Interfaces
Divers
Thread ID:
01278205
Message ID:
01278205
Vues:
88
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;
            }
        }

    }
}
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform