How to establish the object-oriented thought of Java
To know Java object-oriented thinking, then I feel I should compare to learn.
First, let's distinguish between "object-based" and "object-oriented."
Object-based, usually refers to the encapsulation of data, and provides a set of methods for encapsulating data operations. For example, the FILE * in the IO Library of C can be viewed as Object-based.
Object-oriented, it adds polymorphism on an object-based basis. Polymorphism means that you can do the same thing with different objects in a uniform way. Of course, these objects can not be completely different, but need to have some commonality, only the existence of these commonalities can be used in the same way to manipulate them. For example, A and B have a common ancestor R in the inheritance relationship, then we can use both A and B to control them using the control method of R.
In fact, there are two concepts, process-oriented and object-oriented, which may be easy to understand.
Object-oriented is relatively process-oriented.
In simple terms, the difference is that make a dog bark, one is a dog barks:
Make Bark (dog)
Dog.bark ()
The object-oriented approach does encapsulate attributes and functionality, but its core is collation and abstraction.
By centralizing the relevant attributes and functions and isolating the parts that can be separated, the complex business logic can be cut into a relatively independent part of each other, reducing the difficulty of development.
So object-oriented is not just about getting a class and stuffing a bunch of stuff into it, what really matters is deciding what classes to construct, the associations between them, and where to put something.
And there's a simpler example.
Give you a task, you have to think about how to do it.
If your way of thinking is: What I do first, what to do ... This is called process oriented ;
If the way of thinking is: I first do something to do it, then do something to do that thing, and then how they cooperate with each other ... This is called object-oriented .
In a more popular sense, object-oriented is an object that will do this for you, and you just need to call that object to do it. And the process is that you have to do it for yourself.
The object-oriented idea of Java