Which statement best distinguishes a class from an object?
8 Object-Oriented Design Online Quiz Questions
Use this free practice quiz with 20 questions to review 8 Object-Oriented Design, test your knowledge, and prepare for your next test or exam.
Which two benefits are associated with composition rather than implementation inheritance? Select all that apply.
- A
It guarantees that no additional objects or delegation will be needed.
- B
It can allow a collaborator to be replaced at runtime.
- C
It can simplify testing by using substitute collaborator objects.
- D
It requires every collaborator to inherit from the containing class.
True or false: The controller guideline recommends placing all application-level coordination directly in low-level data objects.
- A
True
- B
False
What design principle places behavior that varies by type behind a common interface so clients can avoid scattered type checks?
Complete the statement: Assign behavior to the object that has the information needed to perform it; this is the guideline.
Which design most clearly demonstrates high cohesion?
- A
A PasswordHasher that only hashes passwords
- B
A UserManager that hashes passwords, sends email, writes audit logs, and formats reports
- C
A class that directly constructs a database driver and formats user messages
- D
A service that combines unrelated reporting, payment, and configuration tasks
Which two practices help limit coupling between modules? Select all that apply.
- A
Depend on stable abstractions.
- B
Make every module know the internal representation of its collaborators.
- C
Pass only necessary information between modules.
- D
Eliminate every collaboration between modules.
True or false: Introducing a ShippingStrategy interface so that new shipping strategies can be added without rewriting the existing checkout algorithm is an example of the Open–Closed Principle.
- A
True
- B
False
According to the Single Responsibility Principle as stated in the material, how many primary reasons to change should a class have?
Complete the statement: When CheckoutService depends on PaymentGateway rather than directly on a payment vendor, the design illustrates the .
A device application has clients that print, scan, or fax, but most clients use only one capability. Which redesign best applies the Interface Segregation Principle?
- A
Require every device to implement one comprehensive OfficeMachine interface.
- B
Put all device behavior in a single base class.
- C
Separate Printable, Scannable, and Faxable capabilities into focused interfaces.
- D
Expose every possible operation through a universal service interface.
Which situation most directly indicates a violation of the Liskov Substitution Principle?
- A
A subtype adds a specialized operation that clients may optionally call.
- B
A subtype throws an exception for an operation that clients validly expect from the supertype.
- C
A subtype delegates an operation to a separate collaborator.
- D
A subtype changes its internal data representation while preserving its contract.
An InvoiceService currently calculates invoice totals, formats invoices as PDFs, sends email, and writes audit logs. Using the responsibility-assignment, cohesion, coupling, and SOLID guidance from the material, propose a redesign. Explain how all four responsibilities should be separated or coordinated, where focused collaborators or meaningful abstractions would be useful, and how you would test the result without coupling tests to private implementation details.
A checkout system must support several shipping algorithms that may be replaced or tested independently. Which design choice best follows the material's guidance?
- A
Use inheritance because any shared code automatically establishes a sound subtype relationship.
- B
Use composition with an injected strategy because shipping behavior can vary independently.
- C
Avoid all abstractions and place every shipping rule in the checkout method.
- D
Create a deep inheritance hierarchy for each combination of destination and shipping speed.
Which statement correctly distinguishes a class from an object?
- A
A class is a particular runtime instance, while an object defines shared behavior.
- B
A class defines shared structure and behavior, while an object is a particular instance.
- C
A class is always an interface, while an object is always a subclass.
- D
A class stores only data, while an object stores only operations.
A bank account must never allow a withdrawal that exceeds its available balance. Which design best applies encapsulation?
- A
Expose the balance as a public field so callers can update it directly.
- B
Move all account behavior into the user-interface layer.
- C
Expose a withdrawal operation that validates whether the balance can support it.
- D
Replace the account object with a collection of unrelated utility functions.
When is inheritance the most defensible design choice?
- A
Use inheritance when the proposed subtype genuinely satisfies the behavioral contract of the supertype.
- B
Use inheritance whenever two classes have at least one field with the same name.
- C
Use inheritance whenever it avoids duplicating any small piece of code.
- D
Use inheritance whenever the subclass needs to disable an operation supported by the superclass.
True or false: The Single Responsibility Principle requires every class to contain only one method.
- A
True
- B
False
What design term describes how closely the responsibilities of a module belong together?
Which SOLID principle says that a subtype should be usable wherever its supertype is expected without breaking valid client assumptions?