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. 子线程创建AlertDialog错误

    Can't create handler inside thread that has not called Looper.prepare()

  2. android 打包工具

    sdk.jar-修改路径-JarToDex-DexToSmali-复制文件

  3. PHP魔术方法__call()篇

    当我们调用类中的方法时,如果方法不存在的话.__call会是运行,从而使错误不显示出来 header('Content-type:text/html;charset="utf-8" ...

  4. Django框架详解之views

    一个简单的视图 一个视图函数,是一个简单的python函数,它接受web请求并且返回web响应.无论视图本身包含什么逻辑,都要返回响应.为了将代码放在某处,约定是将视图放置在项目或应用程序目录中的名为 ...

  5. STL中的迭代器的使用

    package com.text; import java.lang.reflect.Field;import java.util.ArrayList;import java.util.Iterato ...

  6. day 06 数据类型的内置方法[数字类型,字符串类型]

    什么是可变还是不可变? 可变是值可以改变,但是ID不变,不可变是值变,ID也变. 1.数字类型 int 1.用途:年龄,号码,等级 2.定义:可以使用int()方法将纯数字的字符串转为十进制的整数 a ...

  7. 一些AngularJs

    # AngularJs部分 #     详情可参考文档----依赖注入--不是主动地获取而是被动的接收,需要什么就要什么,这样灵活较高,如:$scope ----指令--内部:ng-    如:ng- ...

  8. JS生成数字加减乘法验证码

    给大家分享一个简单的js验证码生成代码 PS:该代码依赖Jquery1.4版本以上 传入元素 如productionVerificationCode(#\(("a")) 反回验证码 ...

  9. AsyncTask 简要介绍

    当Android的UI线程超过5s未响应时,系统会引发ANR(Application Not Responding)异常,所以一般不在UI线程中执行耗时任务.一般是在其他线程中处理耗时任务,然后及时更 ...

  10. Java 中关于default 访问权限的讨论

    Java中关于成员变量访问权限问题一般书中会给出如下表格: 简单地描述一下表中的内容:用private 修饰的成员变量只能在类内部访问:用default修饰的成员变量可以再内部访问,也可以被同个包(同 ...