Do not make abstractions if you do not need them now.
Do not make abstractions if you do not need them now. My Take on Clean Code Chapter 6: Objects and Data Structures
Yes, abstractions are powerful. But unnecessary abstractions, especially those that “prepare for the future”, often just add complexity. Hide implementation only when it serves a real purpose. Otherwise, plain data is fine.
Here is a summary of the key ideas:
✅ Data abstraction means expressing the intent of data, not its form ✅ Hiding implementation does not mean putting functions around variables ✅ Prefer interfaces that reflect intent, like “getPercentFuelRemaining”, instead of “getGallons” ✅ There is a fundamental trade-off between objects and data structures
Objects: Hide data Expose behavior Easy to add new types Hard to add new behaviour
Data structures: Expose data No meaningful behaviour Easy to add new behaviour Hard to add new types
There is no one right choice. Mature developers know when to use objects and when to use plain data.
✅ Do not create hybrids that try to do both. They are the worst of both worlds ✅ Follow the Law of Demeter: talk to friends, not to strangers ✅ Avoid “train wrecks” like ctxt.getOptions().getScratchDir().getAbsolutePath() ✅ Instead, hide internal structure, for example, with ctxt.createScratchFileStream() ✅ Data Transfer Objects (DTOs) are okay, especially for database or network I/O ✅ “Beans” with getters and setters are just DTOs with extra ceremony Conclusion
Objects are great when you want to support many kinds of data. Data structures are ideal when you need to support various types of operations.
Good software developers do not follow ideology. They choose based on what they actually need, not what they might need someday.
#CleanCode #SoftwareDevelopment #OODesign #DataStructures #DeveloperExperience #RethinkCleanCode

Kommentieren und diskutieren können Sie direkt unter dem Beitrag auf LinkedIn.