Chapter 10. Complexity
Object-oriented programming increases the value of these metrics by managing this complexity. The most effective tool available for dealing with complexity is abstraction. Many types of abstraction can be used, but encapsulation is the main form of abstraction by which complexity is managed in object-oriented programming.
Rebecca Wirfs-Brock and Brian Wilkinson, “Object-Oriented Design: A Responsibility-Driven Approach”
10.0 Introduction
According to David Farley, if you want to be an excellent software engineer, you need to be an expert at learning, and your only duty is to keep accidental complexity at the lowest possible levels. Complexity is present in every large software system and is often the main source of problems. One of the core differences between a young software developer and a more experienced one is how they manage accidental complexity and keep it at a minimum.
10.1 Removing Repeated Code
Problem
You have duplicate behavior in your code. Duplicated behavior is not the same as duplicated code since code is not text.
Solution
You need to find the missing abstraction and move the repeated behavior there.
Discussion
Duplicated code hurts maintainability and violates the don’t repeat yourself principle. It also increases maintenance costs, and changes can become time-consuming and error-prone. If the code has a defect, it might be present in multiple places. Duplicated code also prevents reusability since there are missing abstractions. ...
Get Clean Code Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.