首页 > Web开发 > 详细

class-metaclass-Class vs. type

时间:2018-01-20 23:40:27      阅读:214      评论:0      收藏:0      [点我收藏+]

In some languages, classes are only a compile-time feature (new classes cannot be declared at runtime), while in other languages classes are first-class citizens, and are generally themselves objects (typically of type Class or similar). In these languages, a class that creates classes is called a metaclass.

 

Class vs. type[edit]

In casual use, people often refer to the "class" of an object, but narrowly speaking objects have type: the interface, namely the types of member variables, the signatures of member functions (methods), and properties these satisfy. At the same time, a class has an implementation (specifically the implementation of the methods), and can create objects of a given type, with a given implementation.[3] In the terms of type theory, a class is an implementation?—?a concrete data structure and collection of subroutines?—?while a type is an interface. Different (concrete) classes can produce objects of the same (abstract) type (depending on type system); for example, the type Stack might be implemented with two classes –  SmallStack (fast for small stacks, but scales poorly) and ScalableStack (scales well but high overhead for small stacks). Similarly, a given class may have several different constructors.

 

Metaclasses[edit]

Metaclasses are classes whose instances are classes.[33] A metaclass describes a common structure of a collection of classes and can implement a design pattern or describe particular kinds of classes. Metaclasses are often used to describe frameworks.[34]

In some languages, such as PythonRuby or Smalltalk, a class is also an object; thus each class is an instance of a unique metaclass that is built into the language. [5] [35][36] The Common Lisp Object System (CLOS) provides metaobject protocols (MOPs) to implement those classes and metaclasses. [37]

 

https://en.wikipedia.org/wiki/Class_(computer_programming)

class-metaclass-Class vs. type

原文:https://www.cnblogs.com/feng9exe/p/8322237.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!