Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Interfaces and Abstract Classes

I'm a little confused as to why/when interfaces and abstract classes would be used. I understand that they provide a "framework" for other classes, but what is the point of doing so?

Thanks for the help.

Comments

  • frazrasheedfrazrasheed Member Posts: 18
    Well, Abstract classes and interfaces provide the specification that must be followed by implementing classes. This provide your application (or program) a lot of flexibility. For example you can write a code like

    interface IDisplayer
    {
    void Display(string msg);
    }

    and in some of your class you may write a method like

    public void doSomething(IDisplayer displayer)
    {
    // some code

    displayer.Display("My name");

    // some code
    }

    Now any kind of displayer can be passed to your method and you can delegate the task of printing the message to it. For example, there can be a displayer to write the message on console, there can be the one that display it in the text box or there is the one that display it on the mobile set. Hence you get a lot of flexibility in your program. In addition to this, the displayer may be using different logics and from different vendors.

    I hope you have got my point!

    Thanks and bye for now
    Faraz

    : I'm a little confused as to why/when interfaces and abstract classes would be used. I understand that they provide a "framework" for other classes, but what is the point of doing so?
    :
    : Thanks for the help.
    :

Sign In or Register to comment.