7 Years
Discussion Span
Last Post by serkan sendur

In theory, every class must have an Interface. The Interface establishes what requests you can make for a particular object.

Votes + Comments
i agree with sknake
No, base classes can also define a "signature" for the class. Interfaces are just another way.

Thanks sknake for your comment.

No, base classes can also define a "signature" for the class. Interfaces are just another way. - sknake

What I said:
In theory, every class must have an Interface. Interfaces add behavior to the class. Is it possible to write classes without behavior?

Consider the following statement -
An object has state, behavior, and identity.


Yes but you are getting in to more abstract CS theory than actual implementation of Interfaces in the .NET framework which the post inquired about.

Interfaces add a signature to the class but are not required as your original post indicated. Static classes cannot descend from a base class nor implement interfaces which means that yes, you can write a class without an interface.

Take these compiler errors:

namespace daniweb
  public static class TestClass
    public static string Prop1 { get; set; }
  public interface ITestInterface
    void DoWork();
  public static class TestClass2 : TestClass
  public static class TestClass3 : ITestInterface


Static class 'daniweb.TestClass2' cannot derive from type 'daniweb.TestClass'. Static classes must derive from object.

'daniweb.TestClass3': static classes cannot implement interfaces

Unless you want to argue that the static class descends from object which is true of all types in .NET, I don't think your point stands. In this case the "Interface" of the class is the class definition itself. If that is what you meant them i'm sure you confused someone trying to understand the meaning of an interface in general, aside from the class definition.


i commented to say that i agree with you sknake, but by reflex although agreeing you means disagreeing adatapost, i appeared to add to his reputation positively :) tomorrow for some reason i need to remove that, as well as the next day :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.