Recommendation 112: Abstract a real-world object into a class and circle reusable objects as namespaces
What is the object in the world around us? Objects are things, commonly known as "things". What, then, is an object? Objects have properties and behaviors. Take animals, for example, cats (cat). Cat can have name, which is the attribute; cat has a bad habit scratchsofa (scratching the couch), which is behavior. The combination of these attributes and behaviors is called a type:
class Cat { publicstringgetset;} Public void Scratchsofa () { Console.WriteLine ("{0} in Flex sofa ", Name); } }
Of course, a type is just a certain kind of object, it refines the interface, standardize the protocol, and the real object is to be produced. For example, Tom Cat, must produce (that is, new) out, in the real world (can be understood as the CLR runtime) really exist (that is, allocating memory). The code is as follows:
Cat Tom =new"Tom"; Tom. Scratchsofa ();
Any "thing" in the software can be understood with this idea.
When we encode the CLR as a real world, and always consider abstracting some objects with common properties and behaviors into one type, we take the first object-oriented step.
Real-life objects can be categorized, which is often a tree-shaped structure. We generalize biology to animals and plants.
The same is true of objects in the CLR, in the case of forms in WinForm, we divide the forms in the system into the background management form and the report foreground form.
In the coding process, we manage the types with packages (folders), and we have the concept of "namespaces". Each node in the namespace, such as the "Manage Forms", represents a taxonomy. Under this node, there is a set of types with properties and behaviors that are relatively close. If the types are not grouped, the chaos will appear immediately. Of course, in agile development, all types or namespaces are not required to be defined in the first place, and as each iteration progresses, the organizational structure of the type can be more logically integrated by refactoring.
Turn from: 157 recommendations for writing high-quality code to improve C # programs Minjia
157 recommendations for writing high-quality code to improve C # programs--Recommendation 112: Abstract objects from the real world into classes, circle reusable objects, namespaces.