He wrote to his look of java tutorial.

1. Object Oriented

"If you want to do the laundry, you can choose to hand wash, but thrown into the washing machine significantly more convenient."

Object oriented design is a programming technique. It will focus on the interface data (ie, objects) and objects. If you want to do the laundry, your first thought is to find a tool will do the laundry (objects), the tools to do the laundry thing, the object here is the washing machine. If you have studied c, c compare the process-oriented design language to do the laundry, for example:

 

c language: the problem into a one step, each step implemented by the function, i.e., dirty clothes into the bowl -> put laundry detergent -> add water -> Hand rubbing -> rinsing -> drying

java: define a washing machine class that contains the methods needed to wash clothes, to create an object of a washing machine, then you have to do it is to put dirty clothes thrown into the washing machine.

 

The pros and cons of the two comparison:

Object-oriented: the relatively high consumption of resources is relatively slow

Process-oriented: the relatively low footprint, relatively fast

 

Such a look as if the object-oriented and process-oriented compared to no advantage at all? And high occupancy, speed and slow, wait, then we have to understand the three characteristics of object-oriented

1. Encapsulation

The so-called package, which is the objective things packaged as an abstract class, and the class can put their data and methods allow only trusted class or object manipulation, hiding on untrusted information.

In the above example, the washing machine is laundry object class encapsulates this feature. Class herein refers to a specification, if a washing machine manufacturers to be manufactured, must be manufactured in accordance with specifications of the washing machine, for example, a drum washing machine must have, have a water inlet, have control buttons and the like. These are necessary to have a washing machine "Properties", while the washing machine but also the most important function of the laundry, have a drying functions, these are the washing machine must be stated in the Specification of "method." Produced in accordance with this specification is out of the washing machine "objects."

As another example, Gree has developed its own norms formulated by the state under the washing machine specifications, Gree production of washing machines must have a fingerprint to unlock function. And other brands of washing machine is not in accordance with specifications to produce Gree washing machine, there is no way to use your fingerprint to unlock features, here similar to the "class can put their data and methods allow only trusted class or object manipulation, untrusted the information hiding "

2. Inheritance

Inheritance refers to such a capability: it can use all the features of an existing class, and without having to rewrite these functions extend the case of the original class.

Or in the washing machine, for example, we have said before, the class is equivalent to the production of standardized washing machines, so it inherited class? If a class inherits another class, then this class is called a subclass inherits class is inherited class is the parent class, subclass can be directly owned parent of all public (public) "property" and "method." Here, Gree washing machine washing machine specification is a subclass of the national standard, Gree produced washing machines must meet all requirements of national standard, and can add their own unique special features.

Inheritance is a relationship of "is-a" relationship, that is a primary school, but one person is not necessarily a relationship between pupils, where the parent class and subclass of the Father and the Son is not the same, after all, the son can not It is his father.

 

3. Polymorphism

Polymorphism is another important feature of object-oriented programming, which refers to a subclass after the properties and methods defined in the parent class inheritance, you may have different data types or exhibit different behavior, which makes the same property or method It has different meanings in each parent and its subclasses. In developed countries, a washing machine specification provides laundry washing machine must be able to have a function, Gree washing machine by ultrasonic washing, other washing machines through water to wash clothes, Gree is dry, the other an ordinary washing.

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zzybot/p/11542373.html