AI Briefing
KO

Improving Code Quality - Session 59: A Class Facade Made of Water

·2025.12.26 11:00

Key point

Rather than excessively separating a class's responsibilities, it's important to keep the interface simple from the caller's perspective.

Details

To minimize the responsibilities of FooValueStore, a data store, there is a design approach that separates the clearAll function, which deletes all data, into a separate class called FooValueStoreClearer.

However, this structure shifts complexity onto the Caller. The caller must understand the relationship between the two objects and check constraints such as whether the two objects need to be the same instance. This violates the Principle of Least Knowledge and makes the design difficult.

When deciding a class's responsibilities, the focus should be not simply on splitting responsibilities, but on the simplicity of the interface exposed to the caller. If the clearAll function is implemented directly inside FooValueStore or defined as an extension function, the caller only needs to manage a single object, making the design much simpler.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.