What is an abstract type?
An abstract type describes what an object can do without requiring its complete representation or implementation.
Study 6 Interfaces and Abstract Types with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is an abstract type?
An abstract type describes what an object can do without requiring its complete representation or implementation.
What is an interface?
An interface is a named contract that specifies operations an implementing type promises to provide.
What does a complete interface contract specify?
A complete interface contract includes names and signatures, input and output rules, behavioral expectations, failure behavior, and state or side-effect expectations.
What must an interface implementation satisfy?
An implementing type must satisfy both the syntactic contract and the behavioral contract of the interface.
How does polymorphism apply to interfaces?
Polymorphism lets client code use the same interface operation with different concrete implementations, each producing implementation-specific behavior.
What is an abstract class?
An abstract class is a partially implemented base class that may provide state, constructors, implemented methods, and abstract methods for subclasses to complete.
When should you choose an interface over an abstract class?
Use an interface for a capability or contract across potentially unrelated types; use an abstract class when related types need shared state or implementation.
What does the dependency inversion principle recommend?
Dependency inversion means high-level policy depends on abstractions, while low-level implementations conform to those abstractions.
What is dependency injection?
Dependency injection supplies a concrete implementation to a client through a constructor, factory, configuration object, or framework.
When are implementations interchangeable?
Implementations are interchangeable when a client can replace one with another without violating the client's assumptions or the shared contract.
Why should interfaces remain focused?
A focused interface represents one coherent responsibility, such as separate Reader and Writer capabilities, instead of forcing unrelated operations together.
What does it mean to design around client needs?
Design an interface around the operations clients actually need, rather than exposing every operation available on the concrete object.