Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Metaobject protocol is protocol for metaobjects in a programming languages. Although I understand it on simple terms, I want to know the reason and a summary of real world usage patterns of this protocol. So, why exactly is metaobject and more importantly metaobject protocol is such a good idea. I want to know the problem which led to its evolution and also, its high power usage. Opinions as well as general overview/description/alternate explanations are also welcome.

share|improve this question
“Metaobject protocol is protocol for metaobjects”? Holy circular definition of fundamental concepts, Batman! – Donal Fellows May 26 '11 at 0:38

Meta-object protocols are very good to decouple clients from servers.

  • Web services use WSDL
  • OSGI does some of this ( but AFAIK lacks a lot of the introspection tools)
  • JINI (Java based) on regular networks ( quite quietly popular in the defence space)

Some control systems I've worked on I added meta-object protocols and it worked really well. The exchange of messages look like this....

  • Dear Server, what do you do ?
  • Dear Client, I have the following commands .....
  • Dear Server, what data do you publish ?
  • Dear Client, I have the following subscribable notifications .....
  • Dear Server please tell me more about "Paint fence"
  • Dear Client, Paint fence takes an integer, number of robots to use.
  • Dear Server, please give me a help file on command "paint fence
  • Dear Client, Here is a help file
  • Dear Server, subscribe me to "robot #1 coordinates"
  • Dear Server, subscribe me to "robot .. coordinates"
  • Dear Server, subscribe me to "robot #42 coordinates"

  • Dear Server, execute paint fence, 42

  • Dear Client, your command completion id is 11.
  • Dear Client, robot #1 coordinates new value 123.3434,34.232312,55.222312

So the overhead of messages you use for real tasks is low because they can even be a compact binary from, and the server is self-documenting for integrators.

Allows integration really easily.

Also allows you to extend the server really easily IF you can add stuff to the server using the meta-protocol. Does start to look like AOP

  • Dear Server, add delegated command FOO (no arguements, "does foo")
  • Dear Client, you are the FOO delegate.

  • Dear Server, override value for external temperature, new value 3.5 So now all consumers get the externally supplied value. Works best if you can ask questions like this..

  • Dear Server, get control value for external temperature

  • Dear Client, external temperature set to external source, hostname SMART_TEMP_SENSOR
share|improve this answer

The Perl library Moose is using the MOP to allow a large ecosystem of extensions to work smoothly together. It also allows for introspection and reflection, for instance the generation of a web form by providing an object. The reflector would look at the class, take (for example) it's attributes or attributes that implement a specific behavior, and generate form fields depending on the attributes and their types.

There are of course many other implementations and use cases for the MOP, Moose is just the one I use most frequently.

share|improve this answer

One way of thinking about a meta-object protocol is that it's like aspect-oriented programming. AOP really came out of MOP, but extended it with point-cuts (and probably other stuff).

So, things that AOP is good for I would expect MOP to be good for. The classic example is, of course, profiling. You want to take an existing program and modify it to e.g. record every method that is invoked. With MOP you could do with this some kind of proxy object which intercepts messages, records the profile data and then passes control onto the original message handler.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.