More on this book
Community
Kindle Notes & Highlights
by
Metz Sandi
Started reading
August 11, 2022
Failures of OOD might look like failures of coding technique, but they are actually failures of perspective. The first requirement for learning how to do object-oriented design is to immerse yourself in objects; once you acquire an object-oriented perspective, the rest follows naturally.
Programmers are not psychics. Designs that anticipate specific future requirements almost always end badly. Practical design does not anticipate what will happen to your application; it merely accepts that something will and that, in the present, you cannot know what. It doesn’t guess the future; it preserves your options for accommodating the future. It doesn’t choose; it leaves you room to move. The purpose of design is to allow you to do design later, and its primary goal is to reduce the cost of change.
in all procedural languages, there is a chasm between data and behavior. Data is one thing, behavior is something completely different. Data gets packaged up into variables and then passed around to behavior, which could, frankly, do anything to it. Data is like a child that behavior sends off to school every morning; there is no way of knowing what actually happens while it is out of sight. The influences on data can be unpredictable and largely untraceable.
When the future cost of doing nothing is the same as the current cost, postpone the decision. Make the decision only when you must with the information you have at that time. Even though there’s a good argument for leaving Gear as is for the time being, you could also make a defensible argument that it should be changed. The structure of every class is a message to future maintainers of the application. It reveals your design intentions. For better or for worse, the patterns you establish today will be replicated forever. Gear lies about your intentions. It is neither usable nor exemplary. It
...more
When the future cost of doing nothing is the same as the current cost, postpone the decision. Make the decision only when you must with the information you have at that time. Even though there’s a good argument for leaving Gear as is for the time being, you could also make a defensible argument that it should be changed. The structure of every class is a message to future maintainers of the application. It reveals your design intentions. For better or for worse, the patterns you establish today will be replicated forever. Gear lies about your intentions. It is neither usable nor exemplary. It
...more
An object has a dependency when it knows: The name of another class. Gear expects a class named Wheel to exist. The name of a message that it intends to send to someone other than self. Gear expects a Wheel instance to respond to diameter. The arguments that a message requires. Gear knows that Wheel.new requires a rim and a tire. The order of those arguments. Gear knows that Wheel takes positional arguments and that the first should be rim, the second, tire.
When two (or three or more) objects are so tightly coupled that they behave as a unit, it’s impossible to reuse just one. Changes to one object force changes to all. Left unchecked, unmanaged dependencies cause an entire application to become an entangled mess. A day will come when it’s easier to rewrite everything than to change anything.
One especially destructive kind of dependency occurs where an object knows another who knows another who knows something; that is, where many messages are chained together to reach behavior that lives in a distant object. This is the “knowing the name of a message you plan to send to someone other than self ” dependency, only magnified. Message chaining creates a dependency between the original object and every object and message along the way to its ultimate target. These additional couplings greatly increase the chance that the first object will be forced to change because a change to any of
...more
depend on things that change less often than you do. This short statement belies the sophistication of the idea, which is based on three simple truths about code: Some classes are more likely than others to have changes in requirements. Concrete classes are more likely to change than abstract classes. Changing a class that has many dependents will result in widespread consequences.
There is design detail that must be captured at this level, but an object-oriented application is more than just classes. It is made up of classes but defined by messages. Classes control what’s in your source code repository; messages reflect the living, animated application. Design, therefore, must be concerned with the messages that pass between objects. It deals not only with what objects know (their responsibilities) and who they know (their dependencies) but also with how they talk to one another. The conversation between objects takes place using their interfaces; this chapter
...more
In the first application, the messages have no apparent pattern. Every object may send any message to any other object. If the messages left visible trails, these trails would eventually draw a woven mat, with each object connected to every other. Figure 4.1 Communication patterns In the second application, the messages have a clearly defined pattern. Here the objects communicate in specific and well-defined ways. If these messages left trails, the trails would accumulate to create a set of islands with occasional bridges between them.

