What is an abstraction?
An abstraction describes what an object can do while hiding the details of how it does it.
Study 6 Interfaces and Abstractions with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is an abstraction?
An abstraction describes what an object can do while hiding the details of how it does it.
What does an interface define?
An interface defines a contract of required operations, properties, or members without normally specifying their implementation.
What is an abstract class?
An abstract class is an incomplete class intended for extension; it may combine abstract members, concrete methods, state, and protected operations.
How do nominal and structural interfaces differ?
Nominal typing requires explicit declaration that a class implements an interface; structural typing accepts a type when it has the required structure.
Why implement multiple interfaces?
A class can implement multiple interfaces, allowing it to support several independent capabilities.
What is polymorphism in this context?
Polymorphism lets one interface-typed variable or parameter refer to objects of different concrete types, each providing its own implementation.
When is an interface preferable?
Use an interface when a capability may apply to unrelated classes or when clients mainly need a small behavior-focused contract.
When is an abstract class preferable?
Use an abstract class when related subclasses should share state, construction rules, protected members, or substantial implementation.
What is dependency injection?
Dependency injection supplies a component’s required object from outside instead of having the component construct or locate it internally.
What does dependency inversion change?
Dependency inversion makes important application logic depend on abstractions while concrete infrastructure implements those abstractions.
What does programming to abstractions mean?
Programming to an abstraction means declaring types using the most general contract that provides everything the code actually needs.
What else does an abstraction contract include?
An abstraction’s contract includes semantics such as error behavior, invariants, copying or referencing rules, thread safety, and expiration—not only signatures.