CSC/ECE 517 Fall 2011/ch2 2c ds

From Expertiza_Wiki
Revision as of 00:21, 20 September 2011 by Dnyayac (talk | contribs) (→‎Mixins)
Jump to navigation Jump to search

Introduction

Interfaces

Mixins

A Mixin is a class that is mixed with a module or a set of modules i.e. the implementation of the modules and the class are intertwined and combined together. This gives us a neat and controlled way of adding new functionality to classes. Modules are similar to classes in that they hold a collection of methods, variables constants and other modules and class definitions.

The real usage of a Mixin is exploited when the code in the Mixin starts to interact with code in the class that uses it. Modules provide a structure to collect Ruby classes, methods, and constants into a single, separately named and defined unit thereby. This is useful so that you can avoid clashes with existing classes, methods, and constants. They help the programmer adhere to the DRY (Don’t Repeat Yourself) principle and allows them to add the functionality of modules into your classes.

Modules are defined in Ruby using the module keyword.

Supported Languages

Multiple Inheritance

Diamond Problem

Approaches

Comparison between Mixins and Interfaces

Advantages and Disadvantages

Conclusion

References

Useful links