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]

Main article: Metaclass

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的更多相关文章

  1. Python中使用type、metaclass动态创建方法和属性

    1: type() 我们知道动态语言和静态语言最大的不同,就是函数和类的定义,不是编译时定义的,而是运行时动态创建的. 比方说我们要定义一个Person的class: class Person(obj ...

  2. python metaclass 入门简介

    http://cizixs.com/2015/08/30/metaclass-in-python 动态类型也是类型 python 是一种动态类型语言,换句话说每个变量可以在程序里任何地方改变它的类型. ...

  3. python 元类——metaclass

    from stack overflow:http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python Classes ...

  4. 关于metaclass,我原以为我是懂的

    关于Python2.x中metaclass这一黑科技,我原以为我是懂的,只有当被打脸的时候,我才认识到自己too young too simple sometimes native. 为什么之前我认为 ...

  5. Mybatis框架基础支持层——反射工具箱之MetaClass(7)

    简介:MetaClass是Mybatis对类级别的元信息的封装和处理,通过与属性工具类的结合, 实现了对复杂表达式的解析,实现了获取指定描述信息的功能 public class MetaClass { ...

  6. Python 面向对象高阶-----metaclass

    Python 面向对象高阶-----metaclass 前言 类也是对象,既然类是对象,那就自然是某个东西的实例化,这个东西就是type 首先看下type是怎么回事 type type最常用的方法就是 ...

  7. python中Metaclass的理解

    今天在学习<python3爬虫开发实战>中看到这样一段代码3 class ProxyMetaclass(type): def __new__(cls, name, bases, attrs ...

  8. 洗礼灵魂,修炼python(42)--巩固篇—type内置函数与类的千丝万缕关系

    type函数的隐藏属性 相信大家都知道内置函数type是用来查看对象的数据类型的.例: 那比如我对int类查看类型呢? 有朋友会说,int是内置类啊,用自定义的应该不会这样,我们自定义一个类呢? 还是 ...

  9. 论type与object的关系----Python创世纪

    这篇随笔的灵感来源于学习源码时对type及object关系的疑惑,主要参考了这篇论文: http://www.cs.utexas.edu/~cannata/cs345/Class%20Notes/15 ...

  10. MetaClass

    它的作用主要是 指定由谁来创建类,默认是type #python3 class Foo(metaclass=MyType): pass #python2 class Foo(object): __me ...

随机推荐

  1. javascript动画函数封装(升级版)

    //把 任意对象 的 任意数值属性 改变为 任意的目标值 function animate(obj, json, fn) { clearInterval(obj.timer); obj.timer = ...

  2. scp 命令简明介绍

    安全复制(英语:Secure copy,缩写SCP)是指在本地主机与远程主机或者两台远程主机之间基于Secure Shell(SSH)协议安全地传输电脑文件."SCP"通常指安全复 ...

  3. idea报错:Please, configure Web Facet first!

    https://blog.csdn.net/handsomepig123_/article/details/87257689  转载

  4. Laravel 多条件搜索查询

    做查询功能时,输入的关键词有的为空,有的有值,如何实现多功能查询呢?这里介绍一种方法.(基于laravel) 原理很简单,第一步:判断接收的值,第二步:写查询语句.具体实现如下: //首先,创建句柄: ...

  5. PHP下的Oauth2.0尝试 - OpenID Connect

    OpenID Connect OpenID Connect简介 OpenID Connect是基于OAuth 2.0规范族的可互操作的身份验证协议.它使用简单的REST / JSON消息流来实现,和之 ...

  6. Vue2+Webpack+ES6 兼容低版本浏览器(IE9)解决方案

    Vue2+Webpack+ES6 兼容低版本浏览器(IE9)解决方案 解决方式:安装 "babel-polyfill" 即可. 命令:npm install --save-dev ...

  7. Python 绘图与可视化 matplotlib(下)

    详细的参考链接:更详细的:https://www.cnblogs.com/zhizhan/p/5615947.html 图像.子图.坐标轴以及记号 Matplotlib中图像的意思是打开的整个画图窗口 ...

  8. Chrome插件Axure RP Extension

    Chrome插件Axure RP Extension 1.将文件夹“0.6.2_0”复制到Chrome文件夹中某个位置. 2.打开Chrome,打开[设置] - [扩展程序],勾选右上角的“开发者模式 ...

  9. 上机题目(0基础)-计算两个正整数的最大公约数和最小公倍数(Java)

    题目例如以下:

  10. HDU 4856 Tunnels(BFS+状压DP)

    HDU 4856 Tunnels 题目链接 题意:给定一些管道.然后管道之间走是不用时间的,陆地上有障碍.陆地上走一步花费时间1,求遍历全部管道须要的最短时间.每一个管道仅仅能走一次 思路:先BFS预 ...