The object-oriented idea of Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.