derived class | inherits | base(parent) class |
---|---|---|
class | implements | interface |
derived interface | extends | base interface |
public class Shape
{ … }
public class Circle : Shape
{ … }
public Circle(int x, int y) : base(x)
{ … }
public interface IDrawable
{
Point StartingPoint { get; set; }
void Draw();
}
An interface has the following properties:
An interface is like an abstract base class. Any class or struct that implements the interface must implement all its members.
An interface can't be instantiated directly. Its members are implemented by any class or struct that implements the interface.
Interfaces contain no implementation of methods.
A class or struct can implement multiple interfaces. A class can inherit a base class and also implement one or more interfaces.
namespace System.Collections.Generic
{
public class List<T> :
IList<T>,
ICollection<T>,
IList,
ICollection,
IReadOnlyList<T>,
IReadOnlyCollection<T>,
IEnumerable<T>,
IEnumerable
{ ... }
}
namespace System.Collections.Generic
{
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
{
T this[int index] { get; set; }
int IndexOf(T item);
void Insert(int index, T item);
void RemoveAt(int index);
}
}
namespace System.Collections.Generic
{
public interface ICollection<T> : IEnumerable<T>, IEnumerable
{
bool IsReadOnly { get; }
void Add(T item);
void Clear();
bool Contains(T item);
void CopyTo(T[] array, int arrayIndex);
bool Remove(T item);
}
}