We all know that object-oriented has three basic features: encapsulation, polymorphism, and inheritance.
Packaging:
I first quoted a user wrote a joke: The basic variables are no longer floating in a large section of the program, they have given up (in fact, programmers do not use this way) this free way of existence, but a stable resident in the huge and faltering "object" inside, separated from the outside world, Connect and communicate with the outside world through circuitous indirect means. And these objects are the survival machines of these basic variables!
In process-oriented development, variables are exposed throughout the program, and an careless modification can result in an entire program error. So encapsulation helps us make our programs more robust. This is very well understood by everyone.
Inherited:
Provides a way to deal with the commonality of the same class of objects, and subclasses inherit something common to the parent class. This facilitates the reusability of the code, which is certainly well understood by everyone.
Polymorphic:
I guess it's the concept that people don't understand, and I've always thought that the overload of the function is polymorphic, and I've seen some of the great God's articles lately to understand a little.
Different classes of objects react differently to the same behavior, and we call it polymorphic. In contrast to inheritance, polymorphism provides a way of dealing with the differences of the same class of objects, and subclasses implement the differences of subclasses by rewriting the methods inherited from the parent class by polymorphic overrides.
Let me give you a simple example to understand:
Class aninal{is called;}//is a way of animals.
Class cat extend animal{called;}
Class dog extend animal{called;}
Animal dog = new Dog ();
Animal cat = new Cat ();
Dog. called ();
Cat. called ();
The polymorphic state here should refer to the form, for example, the dog can have animal form, the real essence is to forget the type of the object, blur the difference between the parent class and the subclass, use the same form to express different behavior! this facilitates the code on the basis of reusability to allow subclasses to express their differences.
In-depth understanding of the three basic characteristics of object-oriented