Object-oriented design concept (OO idea, object oriented)
1. You should not write code directly when you see a requirement. You should first consider what classes are available.
2. When considering classes, a class must be a description of a class of transactions, not too restrictive.
3. When considering classes, you need to consider the main classes, which are those that need to be closely related to business, actions, and events.
Do not consider the time of the class too divergent. First consider the main class, and then by the main push, a bit of the class you consider, may just
An attribute of an existing class. When considering attributes, it is important to note that if there are other attributes in the current class of the property compared to the degree of variability
Too high, you should consider stripping out (that also needs specific considerations, but generally this is the case).
4. Attribute: Do not need to declare all the properties of the class, just need to use their own. such as: Human, attribute thousands,
Don't write them all, just declare what you need according to your needs.
5. Properties are generally private, providing get, set method area operations. Because if you open the permissions of a property directly, it's hard to define what
Object can be accessed, if it is a method, if I want to get some objects to access, I can restrict in get, set, so that I can
Better to control my own properties access to the permission, at least more than the property directly open to be safe, according to the principle of object-oriented, so the general properties are private.
6. Method: When considering the encapsulation method, you are standing in the position of the class to consider the method.
such as: Car class method, suppose you are a car, what do you think you will have to do with the car to do the subject to consider: like, I can run
7. Hide and package: Reduce the coupling degree. The single duty of the class "Handle your own business", "just deal with yourself, don't do too much chores"
Do not have too much involvement with your own classes and objects that are not very dense, only with your closest classes and objects.
8. To add or harden features, you should first think of extensions (overrides or overloads, etc.) rather than modifications. Aggregation rather than inheritance.
9. When there are too many classes of similar types, we will have to write the same or similar code a lot more, then we should think of inheritance.
10. The code in classes that inherit the same type is much less, but the drive class that executes or handles these objects is also a different class object that handles many of the scoring situations.
All at this point, we can use the polymorphic way to point to the subclass object with the parent class reference. This solves the different methods of dealing with multiple objects.
(Inheritance is a matter of careful consideration, as inheritance is one of the important embodiment of the increase in coupling) * * * * *
11. Because inheritance is strongly coupled, inheritance can inherit only one class, meaning that a subclass has only one parent class. So if there is a case to inherit more than one parent class,
Then it can be implemented. That is, the parent class is defined as an interface. A class is capable of implementing more than one class. And the interface can also be polymorphic.
12. Share with you my subtle differences in the design of interfaces and abstract classes: Not very well described, I hope you understand.
1> If you are simply describing the explicit public features and functions of a class of things and several kinds of things, you use interfaces.
2> If you are designing a class that is already relatively clear and some of it is to be implemented, but you are not sure how to implement it, then you are designing abstract classes.
12.***: Refers to a child class object with a parent or parent interface reference. Object-oriented core, the most essence of the idea, but also the late expansion and maintenance of an important indicator, but also can not be arbitrarily used oh, do not over-design. (Polymorphism is the premise of inheritance and implementation)
13. Design is not wrong, just to grasp a degree, can not design, do not over design, according to the actual design, design also do not rush, and one step, design is a gradual,
Also do not deliberately and framed to die your project, do not design for the design.
---------------------
Running snail
Source: CSDN
Original: 59638426?utm_source=copy
Copyright NOTICE: This article is for bloggers original article, reprint please attach blog link!
Object-oriented design idea