This chapter refers to the common mistakes that novices make when designing.
I like this chapter most, before looking at the time, in order to pursue the so-called speed, the book of the examples are all skipped, really a bit maiduhuanzhu taste. Also explain why the reading notes suddenly jump to the 11th chapter.
The simplest reason is because I have a feeling about this chapter and feel the need to take notes.
The following are common:
1. A class without methods (Missingmethods). There is no value for the class without methods, "programs is about behavior!", we should divide the software system according to the behavior. If the software is not broken down according to the behavior, the other error partitioning method is used.
2. Vacuum Class (Vapor Classes). There is a light class, this class has no data members, there are only two methods: on and off, these two methods also do a simple conversion, the method is only one sentence, called the COFFEEMAKERAPI function, did not do anything meaningful, remove it completely does not affect the software logic. In addition to light, buttons, boiler, and warmerplate are also classes that remove the logic without any effect.
3. Hypothetical abstraction (imaginary abstraction). Because the coffee machine needs to be described in the description of several heaters and sensors, beginners will take for granted a sensor of the abstract base class. How to determine whether the base class is reasonable? See if there are any other classes that will use it. In addition, if the interface of an abstract class is too generalized, it is also a hint of error abstraction. The hypothetical base class arises because people pick a noun from it according to the requirements specification, and then extract the abstraction from these nouns.
4. God-like Class (Classes). If all the responsibilities are in one class, you may have created an all-rounder class. The Universal class is what we want to avoid, and that's why we do the design.
With so many mistakes and cautions, how do you design the right coffee machine program?
"The trick to solving this problem are to step back from the problem and separate the
Details from the essential nature of the problem. Forget about boilers, valves, heaters, sensors,
The little details of the problem and concentrate on the underlying problem.
What is this problem? The problem is:how do you make coffee?
How does the Make Cofee? The simplest, and most common solution to this problem, is
To pour hot water over coffee grounds, and to collect the resulting infusion in some kind of
Vessel. Where do we get the hot water from? Let's call it a hotwatersource. Where do
We collect the coffee? Lets call it a Containmentvessel. "
As the book says, ignore the details and see the nature of the problem.
Boiling the coffee is to pour the hot water on the coffee residue, and then use a container to receive the filtered water. So the coffee machine consists of two things: Hotwatersource and Containmentvessel. What is the dependency between the two classes? It is not right for beginners to map the upper and lower directions of the orientation to the dependency of the class. The dependency of a class should reflect the flow of the message, in fact who sent it to whom. This connection error is referred to in the book as crossed Wires.
Is it enough to have these two classes? Enough. Also add the user interface, otherwise users will not be able to use the coffee machine. To do this, the author adds the UserInterface class, which is responsible for everything that interacts with the user.
How does this ternary group work together? How to determine the behavior of each class? The answer is to trigger from the behavior, using the use case to see what messages between these three classes need to be passed. You can use collaboration diagrams to express relationships. After you have completed the dynamic diagram, you can also draw a static class diagram.
Both static and dynamic graphs are there, so it's over? I think that's almost it. But the author says "No, No, no" (OK, this is what I imagined).
The ideal coffee pot has been designed, immediately put it in the code to achieve it!
The author mentions that if the details of the M4 coffee pot are blended into a class that has just been designed, then the abstract work has just been done in white. For the design to be reusable, you must separate parts that cannot be reused. So there's the back "use Case 1." User pushes Brew button (Mark IV). The general book is from life to art, this chapter of the author from Art to life, unexpected, refreshing.
<<UML for Java programmers>> 11th reading notes