|
|
(One intermediate revision by the same user not shown) |
Line 1: |
Line 1: |
| <big>'''Mixin versus Interface'''</big>
| |
|
| |
|
| __TOC__
| |
|
| |
| ==Introduction==
| |
| == Concepts to explore==
| |
| == Definition==
| |
| === Multiple Inheritance===
| |
| Multiple inheritance is a feature of some object-oriented computer programming languages in which a class can inherit behaviors and features from more than one superclass.
| |
| (From Wikipedia, http://en.wikipedia.org/wiki/Multiple_inheritance)
| |
|
| |
| === Interfaces in Java===
| |
| http://download.oracle.com/javase/tutorial/java/concepts/interface.html
| |
|
| |
| === Modules in Ruby===
| |
| Modules in Ruby are a way to group together methods, classes and constants. They are similar to namespaces in languages such as C++. (From lecture 6 note)
| |
| === Mixin using Modules===
| |
| The most interesting use of modules is to define mixins. When you include a module within a class, all its functionality becomes available to the class. Not only can modules contain class methods; they can also contain instance methods. (From lecture 6 note)
| |
|
| |
| = Advantage and Disadvantage =
| |
| == Mixin==
| |
| === Mixin Advantage===
| |
| === Mixin Disadvantage===
| |
| == Interfact==
| |
| === Interface Advantage===
| |
| === Interface Disadvantage===
| |
| = Examples=
| |
| == Comparable==
| |
| === Ruby Implementation===
| |
| === Java Implementation===
| |
|
| |
| == Singleton==
| |
| === Ruby Implementation===
| |
| === Java Implementation===
| |
| <pre>
| |
| public class Singleton {
| |
| private static final Singleton instance = new Singleton();
| |
|
| |
| /**
| |
| Private constructor prevents instantiation from other classes
| |
| **/
| |
| private Singleton() {
| |
| }
| |
|
| |
| public static Singleton getInstance() {
| |
| return instance;
| |
| }
| |
| }
| |
| </pre>
| |
| == Enumerable==
| |
| === Ruby Implementation===
| |
| === Java Implementation===
| |
| == DataMapper==
| |
|
| |
| === Ruby Implementation===
| |
| === Java Implementation===
| |
| = Unique Use Cases=
| |
| == Mixin Only Use Cases==
| |
| == Interface Only Use Cases==
| |
| = Reference =
| |