What is a class? What is an object?

Source: Internet
Author: User

What is a class?  What is an object? Do you fully understand the meaning of what they represent?
Examples of comparisons in the real world: Human = class, Zhang San = object; dog = class; Our family died in the previous few years rhubarb = object; Chinese = class; Andy Lau = Object ... Many, many examples, the concept of class can be very large, can also be smaller, for example, you can think of humans as a class, but also the Chinese, Americans or men, women as a class, which involves the concept of class inheritance.
Therefore, it is not difficult to understand that the relationship between classes and objects is the relationship between "group" and "individual", one is the concept, one is the entity, with the current very popular "palace" of the lines to explain the class: "You see or see me, the class is there, no increase no less ~ ~ ~ You use or do not have me, the object is there, not sad not happy ..." , you know, in your daily life you say you want to talk to the Chinese and want to have tea with the Americans?  No way? You're going to want to work, live, and communicate with a specific person, the same truth, in object-oriented programming, it is the object that is directly related to the business, not the class, but the class is used to define the shape of the object, how to define it? The variables and constants in the class indicate what kind of properties the object will have after this class, which is equivalent to defining a person with limbs, nose and eyes ... The function (method) in the class shows what kind of ability the object will have, or what it can do! Just as people have the ability to eat and drink and have sex.


I think understanding the concise relationship between the object and the class, your problem is not difficult to solve, when you need to create a class?
1. When creating a model based on the business, that is, you have to write a program to put the elephant in the refrigerator, you have to create at least three classes: an elephant, a refrigerator class, and a can put the elephant in the refrigerator of a certain biological class bar
2. Code that can be abstracted and conceptualized in your business can be organized into classes. For example, your business needs a lot of root, factorial and other mathematical logic operations, although the Java API can be implemented, but you need to call the API to write your own method every time, then when you find that you can use these common methods written in public, You'll wonder why you don't wrap these helpful tool functions in a class, and it's not easy to unify when calling, and you're abstracting out the tools in your business, and this class, for your business, is a toolbox that fits perfectly with the above-mentioned class characteristics.
3. Similar to the above tool class, sometimes a business process is the need to abstract a class out, and finally your project will be described above so large and small countless model classes, business processing classes, tool class composition, think carefully, this is a great model, like the assembly line factory in the assembly line machine, Each of them do their own expertise, do not consider other aspects, what we need to do is how to effectively organize these links together.


Reference website: http://zhidao.baidu.com/question/305471262.html?qbl=relate_question_0&word=%C3%E6%CF%F2%B6%D4%CF%F3

What is a class? What is an object?

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.