What distinguishes a class from an object?
A class is a blueprint defining shared data and operations; an object is a particular runtime instance of that class.
Study 8 Object-Oriented Design Principles with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What distinguishes a class from an object?
A class is a blueprint defining shared data and operations; an object is a particular runtime instance of that class.
What three characteristics commonly define an object?
An object combines state, behavior, and identity. State is its data, behavior is what it can do, and identity distinguishes it from other objects.
How does encapsulation protect an object?
Encapsulation combines state with behavior and controls access to the representation, allowing the object to protect its invariants.
When is inheritance a sound design choice?
Inheritance is appropriate when a subclass genuinely satisfies the parent type’s behavioral contract, not merely when it can reuse a few methods.
What does polymorphism allow?
Polymorphism lets code use a common type while the actual object supplies the implementation that runs.
What does an interface provide?
An interface defines a contract or capability without requiring clients to know its implementation.
What is composition in object-oriented design?
Composition constructs an object from collaborators that perform parts of its work, allowing behavior to vary by supplying different collaborators.
What does the Information Expert principle prescribe?
The Information Expert principle assigns an operation to the object that has the information needed to perform it.
Which class should usually create an object?
The Creator rule assigns creation to a class that closely uses, aggregates, contains, or records the object being created.
What does cohesion measure?
Cohesion measures how closely a class’s responsibilities belong together. High cohesion means the class has a focused, meaningful purpose.
What does coupling measure?
Coupling measures how strongly one class or module depends on others. Good design aims for few, stable, explicit dependencies on suitable abstractions.
What is dependency injection?
Dependency injection supplies collaborators from outside an object instead of having the object construct them internally.