12 Feb 08:40
A proposal for Groovy 2.0: Mixins
From: Daniel.Sun <realbluesun@...>
Subject: A proposal for Groovy 2.0: Mixins
Newsgroups: gmane.comp.lang.groovy.jsr
Date: 2007-02-12 07:42:06 GMT
Subject: A proposal for Groovy 2.0: Mixins
Newsgroups: gmane.comp.lang.groovy.jsr
Date: 2007-02-12 07:42:06 GMT
Hi all, I'm a aficionado of Groovy, so I want Groovy good enough to beat Ruby. When I learnt Groovy, I found nothing corresponding to Mixins in Ruby which is very powerful for programmer to improve productivity. If Groovy wants to have something like Mixins, it can leverage AspectJ. "Inheritance and Mixins Some object-oriented languages (such as C++) support multiple inheritance, where a class can have more than one immediate parent, inheriting functionality from each. Although powerful, this technique can be dangerous, as the inheritance hierarchy can become ambiguous. Other languages, such as Java and C#, support single inheritance. Here, a class can have only one immediate parent. Although cleaner (and easier to implement), single inheritance also has drawbacks—in the real world objects often inherit attributes from multiple sources (a ball is both a bouncing thing and a spherical thing, for example). Ruby offers an interesting and powerful compromise, giving you the simplicity of single inheritance and the power of multiple inheritance. A Ruby class has only one direct parent, so Ruby is a singleinheritance language. However, Ruby classes can include the functionality of any number of mixins (a mixin is like a partial class definition). This provides a controlled multiple-inheritance-like capability with none of the drawbacks. We’ll explore mixins more beginning on page" cited from "Programming Ruby" Best regards, Daniel.Sun(Continue reading)
RSS Feed