Interfaces, abstract classes, structs & records
These C# type forms solve different design problems and should not be treated as synonyms.
Interface vs abstract class
An interface describes a capability or contract that unrelated types can implement. A class can implement multiple interfaces. An abstract class can combine abstract members with shared state, constructors and implemented behavior, but a class can inherit from only one base class.
public interface IHealthCheck
{
bool IsHealthy();
}
public class ApiHealthCheck : IHealthCheck
{
public bool IsHealthy() => true;
}Structs and records
A struct is a value type and works best for small value-like data where copy semantics make sense. A record is designed for data-centric models and provides value-based equality by default. record is a reference type; record struct is a value type.
public readonly record struct Coordinate(int X, int Y);
var first = new Coordinate(10, 20);
var second = new Coordinate(10, 20);
Console.WriteLine(first == second); // TrueKey points
- Interface: behavioral contract that many unrelated types can implement.
- Abstract class: shared base behavior/state plus incomplete members.
- Struct: value type with copy semantics.
- Record: data-oriented type with value equality semantics by default.