An interface is a C# contract that specifies the members a type can implement. For an abstract data type, it turns user needs into a precise boundary: legal operations, observable effects, and required behavior come before the data structure. This separation lets an implementation change while clients depend on the same operations. section 2.2 section 3.1
Design an interface by deciding what clients need before choosing how the type stores its data:
- Name the values and operations that are legal, such as pushing, peeking, popping, and checking whether a collection is empty. section 2.2
- Represent immutable updates with operations that return a new interface value instead of modifying the existing object. section 2.2 section 3.1
- Expose enumeration when the abstraction is a sequence, and choose its natural direction explicitly. section 2.2 section 3.1
- Evaluate the implementation afterward, including whether the promised operations remain cheap regardless of collection size. section 2.2 section 3.1
Stack and deque contracts
A stack interface can inherit IEnumerable<T> and declare Push, Peek, Pop, and IsEmpty. A deque extends the idea to both ends with PushLeft, PushRight, PopLeft, PopRight, Left, Right, and IsEmpty. Implementations can then provide immutable stacks or deques behind these contracts.






