True or false: In object-oriented design, a class is a blueprint and an object is a particular runtime instance of that class.
8 Object-Oriented Design Principles Online Quiz Questions
Use this free practice quiz with 20 questions to review 8 Object-Oriented Design Principles, test your knowledge, and prepare for your next test or exam.
Which object-oriented concept combines an object's state and behavior while controlling how other objects access them?
- A
Inheritance
- B
Encapsulation
- C
Polymorphism
- D
Composition
An Order object owns its order lines and must calculate a subtotal. According to the Information Expert principle, where should the subtotal calculation usually belong?
- A
Assign subtotal calculation to whichever class has the most methods
- B
Assign subtotal calculation to Order because it owns the order lines
- C
Assign subtotal calculation to the database repository because it stores orders
- D
Assign subtotal calculation to the user interface because it displays the subtotal
Which three are benefits of dependency injection as described in the material? Select all correct choices.
- A
Required collaborators are visible at construction time
- B
The class must construct every collaborator internally
- C
Production and test implementations can be substituted
- D
Tests can use stubs, fakes, or other test doubles
True or false: Inheritance is risky when it is used only to reuse a few methods, because it can create a strong dependency on the parent's implementation.
- A
True
- B
False
What design approach emphasizes assigning responsibilities to collaborating objects and defining their roles and contractual relationships?
Complete the statement: A class whose responsibilities form a focused purpose has , while a design in which classes have few, stable dependencies aims for .
A loop stores Circle and Rectangle objects as Shape values and calls shape.area() without checking each concrete class. What design concept explains how the appropriate implementation runs?
- A
The loop must determine each shape's concrete class before calling area
- B
The loop copies the area algorithm into every shape object
- C
Each shape supplies its own implementation of area through a common type
- D
The loop can call area only on Circle objects
Which three statements correctly describe why a design might favor composition over inheritance? Select all correct choices.
- A
Different collaborators can provide alternative behavior
- B
Implementation choices can vary without changing the coordinating object
- C
Inheritance is never appropriate in any design
- D
A design can depend on a meaningful contract rather than a concrete implementation
What design heuristic recommends asking an object to perform an operation instead of extracting its data and performing that operation elsewhere?
Complete the statement: The rule helps assign object creation to a closely related class, while the selects concrete implementations and assembles application objects.
Design an object-oriented solution for notifying customers about shipped orders. Explain which objects should own shipment eligibility, coordination, message content, delivery, and persistence, and explain why your assignments support changeability and testability.
Which design best applies dependency inversion when an ordering policy may use Stripe today and another payment provider later?
- A
CheckoutService constructs StripePaymentProcessor directly so the policy knows its exact provider
- B
PaymentProcessor depends directly on CheckoutService's database schema
- C
CheckoutService depends on PaymentProcessor, while the application boundary supplies StripePaymentProcessor
- D
Each concrete payment provider must expose its internal configuration to the checkout policy
Which statement best distinguishes a class from an object?
- A
A class is a runtime instance, while an object is a blueprint.
- B
A class is a blueprint, while an object is a particular runtime instance.
- C
A class stores only behavior, while an object stores only state.
- D
A class and an object are two names for exactly the same concept.
Which assessment best applies the principle of cohesion?
- A
A class that contains many methods always has high cohesion.
- B
A class is cohesive when it has no dependencies on other classes.
- C
A class that calculates totals, sends email, writes database records, and formats HTML is likely to have low cohesion.
- D
A class has high cohesion whenever it is divided into many small methods.
An Order object owns its order lines, and the system must calculate the order subtotal. Which responsibility assignment best follows the Information Expert principle?
- A
Assign subtotal calculation to Order because it owns the order lines.
- B
Assign subtotal calculation to a user-interface class because users request it.
- C
Assign subtotal calculation to every individual order line and add the results in the controller.
- D
Assign subtotal calculation to the database repository because it persists orders.
Given a collection typed as List<Shape>, a loop calls shape.area() without checking whether each element is a circle or rectangle. What design concept explains this behavior?
- A
The loop must create a separate conditional branch for every shape subtype.
- B
The Shape type stores the area of every shape in advance.
- C
Polymorphism requires all shape subtypes to use the same area formula.
- D
Each concrete shape supplies its own area implementation through the common Shape type.
True or false: Under the Dependency Inversion Principle, an ordering policy should depend directly on StripePaymentProcessor rather than on a stable PaymentProcessor abstraction.
- A
True
- B
False
What object-oriented concept names the characteristic that distinguishes one object from another even when their initial state is identical?
What design term names the part of an application responsible for assembling objects and selecting their concrete implementations?