mixin

How to use the [mixin] tag in AS3 applications?

I have the following two projects in in Flex Builder 3: One AS3 library project (generates a SWC file) One Flex application project (MXML Application) The MXML Application references to the AS3 library project (Flex build path). So far, so good. I now want to run code automatically when an application uses the AS3 library. The [mixin...

Why does DataMapper use mixins vs inheritance?

So I'm just curious about this: DataMapper uses a mixin for its Models class Post include DataMapper::Resource While active-record uses inheritance class Post < ActiveRecord::Base Does anyone know why DataMapper chose to do it that way (or why AR chose not to)? ...

How do I write a hygienic Ruby mixin?

Say I'm writing a mixin module that adds functionality to a third-party class. Obviously some of the methods and instance variables I want to make accessible to the third-party class and its clients. These constitute the public interface of the mixin module. But I want certain other methods and instance variables to be encapsulated. I d...

Objective-C category compared to Mixins

Is the concept of the Objective-C categories in anyway similar to the concept of mixins? If so: what are the similarities? In not: what are the differences? ...

ruby inheritance vs mixins

In Ruby, since you can include multiple mixins but only extend one class, it seems like mixins would be preferred over inheritance. My question: if you're writing code which must be extended/included to be useful, why would you ever make it a class? Or put another way, why wouldn't you always make it a module? I can only think of one r...

Problem with mixins in a MooseX::NonMoose class

Consider the following: package MyApp::CGI; use Moose; use MooseX::NonMoose; use Data::Dumper; extends 'CGI::Application'; BEGIN { print "begin isa = " . Dumper \@MyApp::CGI::ISA; }; print "runtime isa = " . Dumper \@MyApp::CGI::ISA; ... The output when this compiles is: begin isa = $VAR1 = [ 'Moose::Object' ...

Rails - Why can't I use a method I created in a module in my tests?

I created a module in lib directory and I can freely call the various methods it contains throughout my Rails app (after adding include ModuleName) with no problems. However when it comes to tests, they complain no such methods exist. I tried including the module into my test helper with no luck. Can anyone help. 4) Error: test_valid_s...

Just-In-Time Derivation

There's a less common C++ idiom that I've used to good effect a few times in the past. I just can't seem to remember if it has a generally used name to describe it. It's somewhat related to mixins, CRTP and type-erasure, but is not specifically any of those things. The problem is found when you want to add some implementation to a clas...

Friend mixin template?

Let's say I have two classes Foo and Bar, and I want to make Foo friends with Bar without changing Foo. Here's my attempt: class Foo { public: Foo(){} private: void privateFunction(){} }; template <class friendly, class newFriend> class friends : public friendly { private: friend newFriend; }; cla...

How do you access an instance variable within a mixin method?

Hi, How do you access an instance variable within a mixin method? I can think of 2 ways, but both seem problematic. Have the mixin method access the instance variable directly as any class method would, e.g self.text. Problem with this is that it places restrictions on where the mixin method can be used, and forces the class doing the ...

Groovy MetaClass - Add category methods to appropriate metaClasses

I have several categories that I use in my Grails plugin. e.g., class Foo { static foo(ClassA a,Object someArg) { ... } static bar(ClassB b,Object... someArgs) { ... } } I'm looking for the best way to add these methods to the meta-classes so that I don't have to use the category classes and can just invoke them as instance me...

Mixins, variadic templates, and CRTP in C++

Here's the scenario: I'd like to have a host class that can have a variable number of mixins (not too hard with variadic templates--see for example http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.103.144). However, I'd also like the mixins to be parameterized by the host class, so that they can refer to its public types (using th...

What does ruby include when it encounters the "include module" statement?

If I have the following project structure project/ lib/ subproject/ a.rb b.rb lib.rb where lib.rb looks like this :- module Subproject def foo do_some_stuff end end and a.rb and b.rb both need to mixin some methods within lib.rb and are both namespaced within a module like so :- require 'subpro...

Accessing a class's containing namespace from within a module

I'm working on a module that, among other things, will add some generic 'finder' type functionality to the class you mix it into. The problem: for reasons of convenience and aesthetics, I want to include some functionality outside the class, in the same scope as the class itself. For example: class User include MyMagicMixin end # S...

Does Objective-C support Mixin like Ruby?

In Ruby, there's Modules and you can extend a class by "mixing-in" the module. Module myModule def printone print "one" end end Class myClass extend myModule end theOne = myClass.new theOne.printone >> one In Objective-C, I find that I have a set of common methods that I want a number of Class to "inherit". What other wa...

Groovy Mixin on Instance (Dynamic Mixin)

I'm trying to achieve following: class A { def foo() { "foo" } } class B { def bar() { "bar" } } A.mixin B def a = new A() a.foo() + a.bar() with one significant difference - I would like to do the mixin on the instance: a.mixin B but this results in groovy.lang.MissingMethodException: No signature of method: A.mixin() is ...

how to add static methods using groovy mixin

hi, I want to use the mixin feature of groovy to import methods as "class(static) methods" instead of instance methods. When i use mixin even though i have a static method in my mixin class it gets converted into a instance method in the destination class.I want the imported method to be a class(static) method.Is there a good way to do...

Qt: Is it possible to use mixins technique?

Hello. Qt library includes advanced meta-programming capabilities using they own preprocessing moc compiler. Does anyone knows, is it possible to create some kind of mix-ins via it? For example, i have a QString and want to add a method to it without sub-classing and changing existing code. Does Qt have such solutions for that? ...

Mixin or Trait implementation in AS3?

I'm looking for ideas on how to implement a Mixin/Trait style system in AS3. I want to be able to compose a number of classes together into a single object. Of course this is not a language level feature of AS3, but I'm hoping that there is maybe some way to do this using prototype based techniques or maybe some bytecode hacking that I...

What is the difference between a mixin and the decorator pattern?

The Decorator Pattern is dynamic extension-at-runtime of classes. It dynamically forms a is-a relationship. I started to wonder if I was over-complicating my API by using the Decorator Pattern after I got this answer about the difference between a mixin and an abstract class. ...