Today, "Software Law", Xu Manshu teacher question: "What is the difference between class and type?" The answer of the public can't be satisfied with the teacher.
After class, Google has an article, is in someone's blog. The end of the article is Xu Jiafu is actually written by Mr. Xu. In the style of the table, the current copy is as follows
Class and type
1: Type concept
Concept: Type scores a set of values and operational operations, which can be understood as a binary group consisting of value sets and operations.
The concept of the type is opposite the concept of the value, the former is the concept of the program, the latter is the concept of the program runtime, and the two are linked by the language components (eg, variables, expressions, etc.) by identifying the value.
For example, the variable V illustrates the value set of type T. Type T is {V1, V2, ... Vn, ...}, then the variable V is running at runtime and can only take a VI as a value. This shows that the type specifies the range of variables or expressions with this type.
2: Class and type
A: common
In the object-type language, "Value" is an object (or object guidance, but it is still object). Therefore, the type in the object language scores a set of objects and the operations on which it can perform. The object scored in the type is called an instance of the type. Class also scraighted a set of objects.
The commonality of the two scored a set of objects and its operations (in the previous discussion, did not emphasize this fact on the operation of the class), so it can be said that the object is Examples of types, it can also be said that objects are examples of classes, types, and classes are the same as the object. However, the type is designed for a set of objects and its operations, and must be used by the class because the class is the sole facility to achieve this purpose. It can be seen that the type is based on class, which is defined by class, which reflects the connection between the two.
B: Difference
L different
Class is the construction unit of the program, which describes a unique language component that describes a set of objects and its operations, which mainly describes the "template" of these objects to create these objects to provide runtime. For example, a derived class definition facility based on a class-based inheritance reflects the role of the class in the description object.
Types are a language component of marker variables or expression value range, which is mainly constrained by the value of these variables or expression runtime. For example, the type matching check of the variables and the right of the value of the assignment statement reflects the constraints of the type.
l Different from the close procedures associated with the object
The specific form of the class description object and the specific operation thereon, and emphasizes the commonality of the set of objects described, and thus, it is closely related to the specific object, and less contact with the size of the object set.
Type emphasizes the range of a set of objects described and the range of operational operations, which is closely related to the size of the object set, and less contact with the specific object.
l is not all types that can be used directly as a type.
Category is the type of type, type category is defined, some classes can be used as types, in which this type can also be called these classes.
However, there are also some classes that cannot be used as a type because, from the type of constraint, the type emphasizes the determinism of the scheduling object, that is, the determinism of the object range. Therefore, only the types determined by the scope of the described object can be used as a type. I think everyone should calm down, read this article carefully. Original: Xu Jiafu