Object, Class & instance__c++ in C + +

Source: Internet
Author: User
C + +, often used objects (object), classes (Class) and instances (Instance) and other concepts, has been a little confused about these concepts, today is to sort out their own ideas, to talk about their views on these concepts bar; Also welcome you to look at their views.

By definition, an object is an entity (Component) that can complete a particular operation with a specific attribute, and a class is a collection with the same Property object (Group of Objects). An instance is often understood as the materialization of an object.

Objects are more of a concept, and in a pure Oo language like Smalltalk, everything is an object (Metaclass, class, instances), and the class is nothing more than a special object that can be created as a template. (Always want to get a Smalltalk to play, but eventually there is no time and energy to learn.) )

In C + +, the concept of "object" is often obscured, and it is not a concept that encompasses everything, but in some circumstances it becomes the concept of being able to replace the class with the instance.

One reason, perhaps, is the definition of a class in C + +. C + + defines a class as an abstract data type (ADT). And ADT is just an implementation concept, it does not exist at run time an object should have characteristics (properties and behavior). Although the Run-time type information (RTTI, see Type_info Class) is introduced in C + +, it is still difficult to treat the class as an object. From this perspective, the class can be seen as synonymous with the concept of objects in the implementation.

For two reasons, the individual feels that it should be related to the context in which these concepts are used. When using C + + (including design patterns), there are often two levels of abstraction to consider:
1. The abstraction when encoding (implementation)
2. Runtime abstraction

In the implementation of C + +, there is no doubt that the concepts of class and object are identical, while instances can be understood as instantiation of a class or materialization of an object, corresponding to design patterns, and those structured schemas (structural Patterns) are more appropriate to this level of abstraction.

At run time, the individual feels that the object is more equal to the instance. We say that an object interacts with another object more by expressing an instance of a class interacting with an instance of another class, when the object is no longer a concept, but is materialized. The behavior pattern in the design pattern (behavioral Patterns) is more appropriate to the abstraction of this level.

The above is my understanding of these basic concepts, please criticize the advice.
Related Article

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.