What do you call the Mixin / Traits object level equivalent, is there a template name for it?

I previously asked about what Mixins are and started to understand the essence of the pattern. But I was wondering if there is a common template name for doing something like Mixins at the Object level as opposed to the class level.

Pseudocode (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 this kind of thing can be done in multiple languages โ€‹โ€‹one way or another, but I'm wondering what the "standard" name for the xxxx function would be, and what the name of that template would be if there was one.

Thank!

Edit: Extending to finnsson's answer. I think it might be different:

 object.xxxx(OtherClass)
 object.otherfoo()

      

Would concatenation be appropriate?

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

+1


source to share


1 answer


This is common in prototype-based programming languages. I believe he called "import" in ruby, but it's a while since the last ruby โ€‹โ€‹programmed, so I'm not sure.

In js / ruby, you should write



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

      

and does not represent any real pattern, as it is just an assignment (o.bar = bar) making perfect sense in a prototype based language. I assume the xxxx in your example can be called a prototype or something similar (see http://en.wikipedia.org/wiki/Prototype-based_programming where the language calls this proto ).

+1


source







All Articles