Metaobject

From Infogalactic: the planetary knowledge core
Jump to: navigation, search

In computer science, a metaobject is an object that manipulates, creates, describes, or implements other objects (including itself). The object that the metaobject is about is called the base object. Some information that a metaobject might store is the base object's type, interface, class, methods, attributes, parse tree, etc. Metaobjects are examples of the computer science concept of reflection, where a system has access (usually at run time) to its internal structure. Reflection enables a system to essentially rewrite itself on the fly, to change the actual structure of the system as it executes.[1]

Metaobject protocol

A metaobject protocol (MOP) provides the vocabulary to access and manipulate the structure and behavior of objects. Typical functions of a metaobject protocol include:[2]

  • Creating and deleting new classes
  • Creating new methods and properties
  • Changing the class structure so that classes inherit from different classes
  • Generating or modifying the code that defines the methods for the class

The metaobject protocol is contrary to the "closed" aspect of Bertrand Meyer's open/closed principle. It reveals and allows a system to modify the internal structure of the objects. For this reason it is usually used sparingly and for special circumstances such as software that transforms other software, for example for reverse engineering.[3]

Runtime and compile time

The original object-oriented languages with metaobject capabilities (e.g., Smalltalk and CLOS) were in interpreted environments so compilation was not an issue. Compilation brings additional complications for a metaobject protocol. For example, it is possible to change the type hierarchy with such a protocol but doing so may cause problems for code compiled with an alternative class model definition. Some environments have found innovative solutions for this, e.g., by handling metaobject issues at compile time. A good example is the product OpenC++.[4]

It is noteworthy that the Semantic web object-oriented model is more dynamic and consistent with run time metaobject protocols. For example, in the Semantic web model classes are expected to change their relations to each other and there is a special inference engine known as a classifier that can validate and analyze evolving class models.[5]

Usage

The first metaobject protocol was in the Smalltalk object-oriented programming language developed at Xerox PARC. The Common Lisp Object System (CLOS) came later and was influenced by the Smalltalk protocol. The CLOS model, unlike the Smalltalk model, allowed a class to have more than one superclass. This provides additional complexity in issues such as resolving which class has responsibility for handling messages defined on two different superclasses. One of the most influential books describing the metaobject protocol in CLOS was The Art of the Metaobject Protocol by Gregor Kiczales.[6]

Metaobject protocols were also extensively used in software engineering applications. In virtually all commercial CASE, reengineering, and Integrated Development Environments there is some form of metaobject protocol to represent and manipulate the design artifacts.[7][8][9]

A metaobject protocol is one way to implement aspect-oriented programming languages. Many of the early founders of MOPs, including Gregor Kiczales have since moved on to be the primary advocates for aspect-oriented programming.

See also

References

  1. Lua error in package.lua at line 80: module 'strict' not found.
  2. Lua error in package.lua at line 80: module 'strict' not found.
  3. Lua error in package.lua at line 80: module 'strict' not found.
  4. Lua error in package.lua at line 80: module 'strict' not found.
  5. Lua error in package.lua at line 80: module 'strict' not found.
  6. Lua error in package.lua at line 80: module 'strict' not found.
  7. Lua error in package.lua at line 80: module 'strict' not found.
  8. Lua error in package.lua at line 80: module 'strict' not found.
  9. Lua error in package.lua at line 80: module 'strict' not found.

External links