For faster navigation, this Iframe is preloading the Wikiwand page for 元对象.

元对象

电脑科学中,元对象(metaobject)是操纵、创建、描述或实现对象(包括自身)的对象。适用于元对象的对象叫做基础对象。元对象可以定义的一些资讯包括:基础对象的类型接口方法特性解析树等。元对象是电脑科学反射概念的例子,这里的系统(通常在运行时间)能访问它自己的内部结构。反射在根本上确使一个系统能现场重写自身,在其运行时改变自己的实现[1]

元对象协议

元对象协议MOP:metaobject protocol)提供了访问和操纵对象系统的结构和行为的词汇表(协议)。元对象协议的典型功能包括[2]

  • 创建或删除一个新类,
  • 创建一个新属性或方法,
  • 致使一个类继承自一个不同的类(“变更类结构”),
  • 产生或变更定义一个类的方法的代码。

进一步的说,元对象协议不只是到底层实现的接口,转而,通过元对象协议,对象系统是依据元对象系统而递归实现的,而它自身在理论上是依据元-元对象系统来实现的,以此类推直到任意一个基础情况(对象系统的一个一致性状态英语State (computer science))被确定,协议就自身而言,是在这些实现层级之间的递归泛函联络。

元对象协议对立于伯特兰·迈耶开闭原则,它声称软件对象系统,应当“开放扩展”而“关闭修改”。这个原则有效的划分了,对其做出增加的扩展对象,和对其重定义的修改对象之间的不同,提出前者是需要的质量(“对象应当可以扩展来满足将来使用情况的要求”),而后者是不需要的(“对象应当提供拒绝概要修订的稳定的接口”)。元对象协议与之相反,透明的暴露对象的内部构成,和就系统自身而言的整个对象系统。实际上,这意味着编程者可以使用对象来重定义自身,可能要以非常复杂的方式。

以元对象协议方式实现对象系统,开放了彻底自主的重新设计的可能性,提供了深度灵活性,但介入了可能的复杂性,和难以理解的元稳定性问题(例如,对象系统不可以破坏性更新它自己的元对象协议,这是它的内部自我表示,但是某些更新的潜在破坏性要预测出来,是件不平凡之事,并可能难以推理),这依赖于想要的修改所传播到的递归深度[3]。由于这些原因,当元对象协议出现于一个语言之中的时候,通常被适度使用并用于特殊用途,比如以复杂方式转换其他软件或自身的软件,例如在逆向工程中用到的那些软件[4]

运行时间和编译时间

在于运行时间不能获得编译的时候,元对象协议的实现就有额外的复杂性。例如,有可能通过这种协议变更类型层级,但是这么做可能导致,用可替代类模型定义编译的代码出问题。一些环境找到了有创意的解决方法,比如通过在编译时间处理元对象问题。一个好例子是OpenC++[5]语义网的面向对象模型,比多数标准对象系统更加动态,并一致于运行时间元对象协议。例如,在语义网中模型类被预期变更它们的相互关系,并有叫做分类器的一个特殊的推论引擎,可以验证和分析演化中的类模型[6]

用途

第一个元对象协议,是在Xerox PARC开发的面向对象编程语言Smalltalk之中的元类。随后的Common Lisp对象系统(CLOS),受到Smalltalk协议,还有Brian C. Smith英语Brian Cantwell Smith3-Lisp作为求值器无穷塔上的原创研究的影响[7]。CLOS模型,不像Smalltalk模型,允许一个类有多于一个超类;这引起了额外的复杂性,比如有解决某些对象实例的类沿袭(lineage)的问题。CLOS还允许动态多方法分派,这是通过泛化函数来处理的,而非Smalltalk的单一分派中的消息传递[8]。描述Common Lisp中元对象协议的语义和实现的最有影响的图书,是Gregor Kiczales英语Gregor Kiczales等人的《元对象协议的艺术英语The Art of the Metaobject Protocol[9]

元对象协议还广泛的用于软件工程应用中。在几乎所有的商业CASE代码重构集成开发环境中,都有某种形式的元对象协议,用来表示和操纵设计工件[10][11][12]

元对象协议是实现面向方面编程的一种方式。很多MOP的早期创立者,包括Gregor Kiczales英语Gregor Kiczales,此后成为了面向切面编程的主要倡导者。PARC雇用了Kiczales等人,为不拥有原生元对象协议的Java设计了AspectJ英语AspectJ

参见

引用

  1. ^ Smith, Brian C. Procedural Reflection In Programming Languages. MIT Technical Report. 1982-01-01, (MIT-LCS-TR-272) [16 December 2013]. (原始内容存档于13 December 2015). 
  2. ^ Foote, Brian; Ralph Johnson. Reflective Facilities in Smalltalk-80. Oopsla '89. 1–6 October 1989: 327–335 [16 December 2013]. ISBN 0897913337. doi:10.1145/74877.74911. (原始内容存档于2021-03-24). 
  3. ^ The Art of the Metaobject Protocol, Appendix C — Living with Circularity
  4. ^ Favre, Lilliana; Liliana Martinez; Claudia Pereira. MDA-Based Reverse Engineering of Object Oriented Code. Springer. 2009. ISBN 978-3-642-01861-9. doi:10.1007/978-3-642-01862-6_21. 
  5. ^ Chiba, Shigeru. A Metaobject Protocol for C++. Oopsla '95. 1995: 285–299 [27 December 2013]. ISBN 978-0897917032. doi:10.1145/217838.217868. (原始内容存档于2013-12-29). 
  6. ^ Knublauch, Holger; Oberle, Daniel; Tetlow, Phil; Wallace, Evan. A Semantic Web Primer for Object-Oriented Software Developers. W3C. 2006-03-09 [2008-07-30]. (原始内容存档于2018-01-06). 
  7. ^ Brian Cantwell Smith, Procedural Reflection in Programming Languages, Department of Electrical Engineering and Computer Science, Massachusetts Institute of Technology, PhD dissertation, 1982.
    3-lisp: an infinite tower of meta-circular interpreters. [2023-01-26]. (原始内容存档于2023-01-26). 
    Daniel P. Friedman; Mitchell Wand. The mystery of the tower revealed. The mystery of the tower revealed: A non-reflective description of the reflective tower. 1988: 298–307 [2023-01-26]. ISBN 978-0897912006. doi:10.1145/319838.319871. (原始内容存档于2023-01-26). 
  8. ^ Integrating Object-Oriented and Functional Programming (PDF). [7 July 2016]. (原始内容存档 (PDF)于2020-07-09). 
  9. ^ Gregor Kiczales英语Gregor Kiczales, Jim des Rivieres, Daniel G. Bobrow英语Daniel G. Bobrow. The Art of the Metaobject Protocol (PDF). MIT Press. 1991 [2022-03-11]. ISBN 0-262-61074-4. (原始内容 (PDF)存档于2022-02-05). 
    The Art of the Metaobject Protocol, Chapters 5 and 6 in Hypertext页面存档备份,存于互联网档案馆
  10. ^ Johnson, Lewis; David R. Harris; Kevin M. Benner; Martin S. Feather. Aries: The Requirements/Specification Facet for KBSA. Rome Laboratory Final Technical Report. October 1992,. RL-TR-92-248. 
  11. ^ The Origin of Refine (PDF). www.metaware.fr. Metaware White Paper. [6 January 2014]. (原始内容 (PDF)存档于7 January 2014). 
  12. ^ OMG's MetaObject Facility. omg.org. Object Management Group. [7 January 2014]. (原始内容存档于2021-05-11). 
  13. ^ OpenC++ Home Page. [2021-03-28]. (原始内容存档于2020-12-05). 

外部链接


{{bottomLinkPreText}} {{bottomLinkText}}
元对象
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?