I used to do the design of the application, at that time just read half the book "Refactoring ...", now it seems that this half of the nine Yin Canon, a lot of income ah. In addition, this is the work of the proof, basically can take out a spray. Of course, it seems that the design of the project was really rotten.
First question, what is design? My answer is: In order to improve the efficiency of program execution, the program according to the module division, and reasonable combination. I will continue to follow these two points, module division and reasonable combination.
The second question, the principle of design? My answer is: low coupling, high cohesion is the only principle of design. Maybe you want to ask me if there are five major principles? Here I will take these five principles one by one.
1 single duty principle. What is a single duty? is a class, or a module that is responsible for a task, a thing. The database module, for example, is responsible for data storage and provides a read-write interface to the data store, and does not care about the business a little. Ask for what? The answer is, in order to improve cohesion.
2 dependency inversion principle. Originally the upper level of the business implementation, the need for the underlying module support, through the parsing of packets, very early use of parsing XML. Now it's parsing json. Then if the upper-level business needs to be modified when switching from XML to JSON, there is no good coupling. Dependency inversion is the solution to this type of problem, which is to abstract the underlying dependencies from the entity to the interface. This interface has two functions, one is the meaning of the contract, who can abide by the contract, who can go on. The second is the meaning of the division, the interface above is the upper business, the following is the implementation unit. Ask for what? The answer is, for low coupling.
3 Richter replacement principle. This is a stricter requirement for base classes and subclasses. That is, no matter how a subclass is implemented, it should maintain the external interface functionality of the parent class so that the class can replace the full replacement parent class, while subclasses with the same functionality can replace each other. A piece of meat, feed to the wolf can, feed the tiger can, feed to the lion can also, but feed to the cow is not. Because the cattle of the parent class is herbivores, there is no meat-eating interface. The answer is low-coupling, easy to transplant.
4 interface Isolation principle. This is a request for the interface, is a peripheral requirement, that is, an interface can not be a irrelevant interface is written in an interface class inside. The interface class should also maintain a single principle of responsibility. But the interface to the irrelevant is to write each one individually. In a word, God was God, and Caesar returned to Caesar. Answer, high cohesion.
5 Dimitri Principle. It means that a class can know as little as possible about its dependent classes. The dependent classes are the least exposed implementations. In a module, the classes between modules are as dependent as possible on the classes in the module, but not outside or with very few external faces exposing classes inside the module. Answer, high cohesion.
The last one is the opening and closing principle. That is, the interface is open, the implementation is closed, so even if the problem is an internal implementation problem, do not modify the interface. To know to modify the interface, it is necessary to modify the dependency class, the change is very large. In fact, the above other principles are to achieve the opening and closing principle. This is also a way to reduce coupling and increase cohesion.
These are too abstract, write a little concrete tomorrow.
Android design casually talk about