views:

90

answers:

1

I previously asked about what Mixins were, and have begun to get the gist of what the pattern means. But it got me wondering if there is a common pattern name for doing something like Mixins at an Object level as opposed to the Class level.

Pseudo code (in some non existent language):

  Class MyClass
  {
     function foo()
     {
        print("foo")
     }
  }

  function bar()
  {
     print("bar")
  }

  object = MyClass.new()
  object.xxxx(bar)

  object.bar() #output: bar

I know stuff like this can be done in several languages, in one way or another, but I'm wondering what would be the "standard" name for the functionality xxxx represents, and what is the name for this pattern, if there is one.

Thanks!

Edit: Expanding on finnsson's answer I guess something like this might be another case of this would be:

 object.xxxx(OtherClass)
 object.otherfoo()

Would concatenate be appropriate?

Quote: "Concatenation: Under pure prototyping, which is also referred to as concatenative prototypes..." -wikipedia

+1  A: 

This is common in prototype-based programming languages. I belive it's called "import" in ruby but it's some time since I last programmed ruby so I'm not sure.

In js/ruby you would write

object.bar = bar;
object.bar() // output: bar

and than it's no real pattern, since it's just an assignment (o.bar = bar) making perfect sense in a prototype-based language. I guess xxxx in your example could be called prototype or something similar (see http://en.wikipedia.org/wiki/Prototype-based_programming where a language calles this proto).

finnsson