1

I have a question regarding interfaces in c#. Currently I am doing an internship and came across the following code:

namespace MyNote
{
public interface INote
{
    double Time { get; set; }
    String Text { get; }
}

public class Note : INote
{
    private double _time;
    private String _text;

    public Note(double time, String text)
    {
        _time = time;
        _text = text;
    }

    public double Time
    {
        get
        {
            return _time;
        }
        set
        {
            _time = value;
        }
    }

    public String Text
    {
        get
        {
            return _text;
        }
    }
}
}

The question: What is the use of this interface? Nobody can answer my question so maybe you guys.

EfhK
  • 123
  • 2
  • 9
  • Are there any other classes implementing `INote`? Is `INote` used as type somehwere? – Christoph Fink Jan 19 '15 at 13:09
  • Nobody in your company knows? You should look for references to `INote` and that should answer your question. There must be a method or something that expects a class that implements that interface, and that `Note` class is just one of them. – Andrew Jan 19 '15 at 13:10
  • For a general info about the usefulness of interfaces: http://programmers.stackexchange.com/questions/108240/why-are-interfaces-useful – Jan Köhler Jan 19 '15 at 13:10
  • 1
    But what is the exact difference in intantiating an interface or a class. The program makes use of a list filled with Inote, but it could have just been Note couldn't it. In my opinion it's not really all that different. – EfhK Jan 19 '15 at 13:16

1 Answers1

1

The main use of interface is code re-usability and to replace multiple inheritance.

You may want to have a look on this and this