asp.net cloud: My relationship with Wei Chunhua is very pure; NetEase said its relationship with the fan butterfly Girlfriend is the training of two-way selection system; Chen Ning-Chen says the thought of "I Ching" hinders the development of modern science in China; The theory of logics: There are five kinds of relations between concepts, that is, the same, including, overlapping, separating and mutual exclusion. But Cantor thinks: the relationship is ordered even.
I want to be lazy + stupid-the ultimate goal of programming
In the early days of the community, "is this a programmer a qualified programmer?" "Hot stickers, the landlord said the code to spend more time than others but the code is robust, ask if such a programmer can be retained and how to use? Suddenly an uproar began in China in this particular environment what is the program design objectives and related project management discussions. The soul catcher uses the old Mao "contradictory theory" the method Analysis: "This is the market and the programmer's contradiction", said "if is the small company's words not to talk about what development ..." Time is the first productive force ... If not ... To solve the management and budget problems first, I can not help but start to admire the ready of its approach.
Regardless of market factors, the primary goal of programming is to successfully solve a realistic problem. It is particularly noteworthy that this practical problem is often dynamic, changes over time, so our code is robust enough to accommodate this process of change, rather than positioning the object to solve a problem at a static point; second, the code and its structure should be concise, and only simplicity makes writing easy, Easy to modify, easy to maintain, and maximize cost savings; Moreover, the code should be reusable, and the greedy idea is that the code can be reused not only in a real problem, but also in the intersection of different reality problems. Finally, because people's understanding of the world is an iterative process and the real problem is changing these two factors, so the program should not affect the original code under the premise of easy expansion. In theory, understand that "everything is the object, everything to be encapsulated", in the face of the experience of the process, you can start to solve any real problem, but you will find that throughout the development process, only with the current knowledge and insights, oneself will be a lot of complex problems entangled, until the abandonment, but these could have been completely avoided! Whether this is the theory or the design pattern, the ultimate goal of all previous experiences is simply to make programming more concise, easier, quicker, and understand this, and it is not difficult for many eminent programmers to claim to be "lazy + stupid".
Separation Relationship-encapsulation and dependency of classes
The world of things can not be like a Robinson island scattered in the endless ocean, ways. On the contrary, even the most remote Motuo County in China remain inextricably linked to the motherland. We know how to put things in real space into objects and abstract them into classes, and then comb the relationships between them.
First of all, we focus on the meaning of encapsulation in the visual angle of programming objectives. From the point of view of the Navigator (the user of the Class), he does not need to understand the island's internal structure of geography and society (Dimitri Law of Demeter), but only to know what the island produces and what it needs (the function of the Class), who is to be traded (public member interface), Knowing this can quickly build a business network (design applications). And as the ruler of the island (the creator of the class), he does not have to pay attention to the outside world, just focus on the island's production and consumption management, the ruler of this phenomenon called high cohesion.
Closure greatly simplifies the complexity of programming, and communication between classes is done through a narrow, well-defined interface to ensure class reliability. On the one hand, the user of the class collects the class rapid development program, and does not attempt to change the internal structure of the class, on the other hand, the implementation of the class can modify the internal working mode without modifying the public member interface.
But the existence of a separate class doesn't make any sense! The most common relationship is when an instance of a class uses an instance of another class, if the merchant shipping Titanic needs Hawaii I. to provide the goods, then we call Merchant shipping Reliance (Dependency) on the islands to provide goods, as shown in Figure 1, and the attendant question is if Hawaii I. internal disturbances ( The implementation of the class modifies the public member interface, which will directly affect the normal work of the Titanic, and we will have to rearrange the internal structure of the Merchant shipping class to accommodate the changes and naught. Coupling is a measure of the degree of dependency between classes, and it is necessary to avoid high coupling when dealing with dependencies in classes with a large likelihood of change.
Inclusion and crossover of concept--the synthesis and inheritance of class
A fool is unable to understand an object stuffed with various complex functions, so the first design principle of the class is unitary and corresponds to a concept in the problem space. If the corresponding concept contains other concepts, but for the whole/partial relationship, called "has-a", we will synthesize the instances of these classes (composition) into a new class. For example, the merchant ships have power plants, then we instantiate a power plant class, plus other properties and methods other than the power plant category, that is, the synthetic merchant shipping class, as shown in Figure 2. Synthesis has great flexibility and does not break the encapsulation of the class. So we want to use compositing as much as possible, less with the inheritance described below (synthetic multiplexing principle composite reuse principle).
Childhood entertainment is relatively small, in the eyes of the box in addition to the landscape, the most than the 560 's war theme of the old film, the characters in the face of the serious, so I always think that the world only two kinds of people-good and bad, if the idea, then the synthesis will indomitable. But in this world, not all of the whole is a simple superposition of parts. Now let's assume that the world's ships have two uses: merchant and warship, from the conceptual point of view, they have a phase, that is, the concept of intersection, as shown in Fig. 6-3, and they also have their own characteristics, if we simply to the merchant ship and warships respectively into two classes, then there will be a large number of class members repeat, Therefore, it is necessary to construct a mechanism to reflect the cross relationship between the two concepts, which is the origin of inheritance (inheritance), called "Is-a".
Inheritance is characterized by a hierarchy, from the shape of the graph looks like a family tree, but the use of family tree to metaphor inheritance is stupid, and does not really reveal the essence of inheritance, inheritance process, is from the general to the special process, as shown in Figure 3 right. Legend has it that humans are descendants of a non-state one, and the fact is that we don't discuss it first, but similarly, if layers are abstract. NET derives directly or indirectly from the same base class--object class.
The most intuitive use of the inheritance of a class is reuse. NET technology gives us the first image is the MS Company engineers after long-term practice of refining more than 5,000 public classes, for applications, it covers almost all areas of the general concept of the current. On this basis, through proper inheritance and synthesis, we will soon be able to construct our own class system.
We look at the class as a collection of members, and for compositing, the members are set as follows:
Merchant Shipping {position, ship direction, power Plant {dynamic Value}, moving (direction)}
The reference power value needs to be expressed in this way: merchant ship, power plant, dynamic value (you can try the "." Read as ""), and for inheritance, its members are set as follows:
• Merchant Shipping {Maximum carrying capacity, load (cargo), Moving (direction)}
• Warship {Firepower value, fight (ship), move (direction)}
It can be seen that the public members of the ship's class become public members of merchant ships, expressed as: merchant ships. The private members of the ship class are hidden in the merchant shipping class. The basis for such treatment is that the merchant ships can move (the famous Aristotelian syllogism) because the ship can move and the merchant ships are ships. Sometimes we want a derived class to be able to access a member of the base class and hide it from a world other than the class. such as the speed of the ship, all kinds of ships should have speed, so speed should be a base class member, but we do not want external factors to directly modify the speed of the computer system to destroy speed (it is also affected by internal and external factors, Calculated by the ship's Move method, so we introduce a third access control character protected to modify the class members.
Warships have an interesting way: fighting (ship), the parameters of an interface are an example of a ship, which means that a warship can fight any kind of ship, no one is a merchant or a warship, so we can use this method: Bismarck. Combat (Titanic), that is, subtype can replace the base type ( This logic can still be proved by Aristotle's Syllogism, which is called the Richter substitution principle (Liskov substitution principle), which is to reduce the complexity of the method implementation.
The inheritance mechanism has an important flaw, and the base class and the derived class are strong coupling relationships, and it breaks the encapsulation, the problem is that if the base class is modified because of improper design, it will affect all derived classes, and for a member of a derived class, it may take you half a day to find out exactly which layer it is implemented. Therefore, in the design process, one should try to compress the number of inherited layers, the second is to adhere to the principle of composite reuse, can be synthesized without inheritance.
Class View of the login class