<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bsampat2</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bsampat2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Bsampat2"/>
	<updated>2026-08-07T16:51:08Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71218</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71218"/>
		<updated>2012-11-20T14:21:52Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
&lt;br /&gt;
The purpose of this Wikipedia page is to give the readers a list of references that explain the Strategy pattern. The references given in this page will give a complete knowledge of this pattern. Further, with each references given in this page a briefing of what it covers, the programming language used and the purpose that it serves is mentioned.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Switch statements=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm &amp;lt;ref name=&amp;quot;Difference&amp;quot;&amp;gt; http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx &amp;lt;/ref&amp;gt; at run time. This explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Inheritance=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
Strategy pattern is used in real life appliactions &amp;lt;ref name=&amp;quot;Application&amp;quot;&amp;gt; [http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf &amp;lt;/ref&amp;gt;. This article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code but demonstrates the importance of strategy pattern in real life.&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
The page includes references that describe the usefulness, advantages and comparison of the Strategy pattern with other methodologies.&lt;br /&gt;
The reader can get a complete knowledge of the pattern by following the references given.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71217</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71217"/>
		<updated>2012-11-20T14:21:43Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
&lt;br /&gt;
The purpose of this Wikipedia page is to give the readers a list of references that explain the Strategy pattern. The references given in this page will give a complete knowledge of this pattern. Further, with each references given in this page a briefing of what it covers, the programming language used and the purpose that it serves is mentioned.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Switch statements=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm &amp;lt;ref name=&amp;quot;Difference&amp;quot;&amp;gt; http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx &amp;lt;/ref&amp;gt; at run time. This explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Inheritance=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
Strategy pattern is used in real life appliactions &amp;lt;ref name=&amp;quot;Application&amp;quot;&amp;gt; [http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf &amp;lt;/ref&amp;gt;. This article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code but demonstrates the importance of strategy pattern in real life.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
The page includes references that describe the usefulness, advantages and comparison of the Strategy pattern with other methodologies.&lt;br /&gt;
The reader can get a complete knowledge of the pattern by following the references given.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71216</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71216"/>
		<updated>2012-11-20T14:18:42Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern, Directory of sites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
&lt;br /&gt;
The purpose of this Wikipedia page is to give the readers a list of references that explain the Strategy pattern. The references given in this page will give a complete knowledge of this pattern. Further, with each references given in this page a briefing of what it covers, the programming language used and the purpose that it serves is mentioned.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Switch statements=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm &amp;lt;ref name=&amp;quot;Difference&amp;quot;&amp;gt; http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx &amp;lt;/ref&amp;gt; at run time. This explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Inheritance=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
Strategy pattern is used in real life appliactions &amp;lt;ref name=&amp;quot;Application&amp;quot;&amp;gt; [http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf &amp;lt;/ref&amp;gt;. This article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code but demonstrates the importance of strategy pattern in real life.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71215</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71215"/>
		<updated>2012-11-20T14:10:52Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern and Inheritance, a comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Switch statements=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm &amp;lt;ref name=&amp;quot;Difference&amp;quot;&amp;gt; http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx &amp;lt;/ref&amp;gt; at run time. This explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Inheritance=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
Strategy pattern is used in real life appliactions &amp;lt;ref name=&amp;quot;Application&amp;quot;&amp;gt; [http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf &amp;lt;/ref&amp;gt;. This article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code but demonstrates the importance of strategy pattern in real life.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71214</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71214"/>
		<updated>2012-11-20T14:10:40Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern and Switch statements, a comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern over Switch statements=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm &amp;lt;ref name=&amp;quot;Difference&amp;quot;&amp;gt; http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx &amp;lt;/ref&amp;gt; at run time. This explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
Strategy pattern is used in real life appliactions &amp;lt;ref name=&amp;quot;Application&amp;quot;&amp;gt; [http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf &amp;lt;/ref&amp;gt;. This article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code but demonstrates the importance of strategy pattern in real life.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71213</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71213"/>
		<updated>2012-11-20T14:10:06Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm &amp;lt;ref name=&amp;quot;Difference&amp;quot;&amp;gt; http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx &amp;lt;/ref&amp;gt; at run time. This explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
Strategy pattern is used in real life appliactions &amp;lt;ref name=&amp;quot;Application&amp;quot;&amp;gt; [http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf &amp;lt;/ref&amp;gt;. This article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code but demonstrates the importance of strategy pattern in real life.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71212</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71212"/>
		<updated>2012-11-20T14:07:03Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern and Switch statements, a comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm &amp;lt;ref name=&amp;quot;Difference&amp;quot;&amp;gt; http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx &amp;lt;/ref&amp;gt; at run time. This explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
[http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf This] article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code or example but demonstrates the importance of strategy pattern in real life.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71211</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71211"/>
		<updated>2012-11-20T14:04:53Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Application */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm at run time. [http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx This] explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
[http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf This] article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code or example but demonstrates the importance of strategy pattern in real life.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71210</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71210"/>
		<updated>2012-11-20T14:04:18Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern, Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm at run time. [http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx This] explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
[http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf This] article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code or example but demonstrates the importance of strategy pattern in real life.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71209</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71209"/>
		<updated>2012-11-20T14:03:59Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern, Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;references/&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm at run time. [http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx This] explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
[http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf This] article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code or example but demonstrates the importance of strategy pattern in real life.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71208</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71208"/>
		<updated>2012-11-20T14:03:18Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern, Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some difficulties &amp;lt;ref name=&amp;quot;Difficulties&amp;quot;&amp;gt; http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html &amp;lt;/ref&amp;gt; when design pattern are not used. This reference gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm at run time. [http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx This] explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
[http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf This] article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code or example but demonstrates the importance of strategy pattern in real life.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71207</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=71207"/>
		<updated>2012-11-20T13:57:39Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern, Directory of sites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable way that can be beneficial for a new reader as well as the programmers that want to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some [http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html difficulties] when design pattern are not used. This article gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm at run time. [http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx This] explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
[http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf This] article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code or example but demonstrates the importance of strategy pattern in real life.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70713</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70713"/>
		<updated>2012-11-19T20:57:44Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern and Inheritance, a comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable language which can be beneficial for a new reader as well as programmer who wants to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and also explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some [http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html difficulties] when design pattern are not used. This article gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm at run time. [http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx This] explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;br /&gt;
&lt;br /&gt;
=Application=&lt;br /&gt;
&lt;br /&gt;
[http://static.usenix.org/publications/library/proceedings/coots97/full_papers/garbinato/garbinato.pdf This] article explains an interesting applications of the Strategy pattern which is to compose reliable Distributed Protocols. This paper does not contain any code or example but demonstrates the importance of strategy pattern in real life.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70708</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70708"/>
		<updated>2012-11-19T20:55:47Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern and Switch statements, a comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable language which can be beneficial for a new reader as well as programmer who wants to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and also explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some [http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html difficulties] when design pattern are not used. This article gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm at run time. [http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx This] explains the advantages of using the Strategy Pattern over the Switch statement.&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Inheritance, a comparison=&lt;br /&gt;
&lt;br /&gt;
[http://docs.doctrine-project.org/en/2.1/cookbook/strategy-cookbook-introduction.html This] is a very good resource that discusses a scenario where Strategy Pattern can be used over Inheritance. It explains the concepts very well and has detailed example in php.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70707</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70707"/>
		<updated>2012-11-19T20:54:15Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern, Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable language which can be beneficial for a new reader as well as programmer who wants to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and also explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some [http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html difficulties] when design pattern are not used. This article gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern and Switch statements, a comparison=&lt;br /&gt;
&lt;br /&gt;
This section directs you to an interesting comparison between the Strategy Pattern and Switch statement both of which can be used to dynamically select an algorithm at run time. [http://blogs.microsoft.co.il/blogs/gilf/archive/2009/11/22/applying-strategy-pattern-instead-of-using-switch-statements.aspx This] explains the advantages of using the Strategy Pattern over the Switch statement.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70705</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70705"/>
		<updated>2012-11-19T20:49:56Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern, Directory of sites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable language which can be beneficial for a new reader as well as programmer who wants to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and also explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Strategy Pattern, Getting Started=&lt;br /&gt;
&lt;br /&gt;
Now that you know the basic definitions and concept of the Strategy pattern, [http://www.oodesign.com/strategy-pattern.html this] will give a deeper insight into the pattern. It explains the motivation behind using the Strategy Pattern and various situations where strategy pattern is useful. A Java example is used to provide better understanding of the concept. Further, it adds some details with regard to implementing a Strategy Pattern such as passing data. It includes a discussion about other patterns that are related to the Strategy pattern.&lt;br /&gt;
&lt;br /&gt;
To gain further insight into the working of the Strategy Pattern, [http://www.codeproject.com/Articles/52807/Design-Patterns-Part-1-The-Strategy-Pattern this] resource gives a precise description with well accompanied example. The example is in C# and is very descriptive and easy to understand. The author of the article has shown how to apply the Strategy Pattern to solve a real problem. Additionally, it discusses some of the implementation problems associated with this pattern. This is a good extension to the previous resource.&lt;br /&gt;
&lt;br /&gt;
Patterns make the code better readable and easy to maintain. There are some [http://www.javaworld.com/javaworld/jw-04-2002/jw-0426-designpatterns.html difficulties] when design pattern are not used. This article gives a comprehensive idea on the disadvantages of not using a design pattern and how the code becomes readable and easy after using the strategy pattern. This resource demands some work from the reader and helps the reader better understand the pattern.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70693</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70693"/>
		<updated>2012-11-19T20:30:57Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Strategy Pattern, Directory of sites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Strategy Pattern is a software design pattern that can be used to select a particular algorithm among many available ones at run time depending on certain conditions. A clear definition of the Strategy Pattern can be found [http://en.wikipedia.org/wiki/Strategy_pattern here]. This resource gives a general idea of the pattern, a useful reference for readers that have not used this pattern before. The reference  is written in a simple and easily understandable language which can be beneficial for a new reader as well as programmer who wants to have a very high level idea about the pattern. It includes a pictorial representation of the fundamental concept behind the pattern and also explains it using an example in Java. This resource includes a discussion about the Open/Close principle and relates it with the Strategy pattern.&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70688</id>
		<title>CSC/ECE 517 Fall 2012/ch2b 2w64 bg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch2b_2w64_bg&amp;diff=70688"/>
		<updated>2012-11-19T20:23:53Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: Created page with &amp;quot;=Strategy Pattern, Directory of sites=&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Strategy Pattern, Directory of sites=&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=70678</id>
		<title>CSC/ECE 517 Fall 2012</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012&amp;diff=70678"/>
		<updated>2012-11-19T20:20:53Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2012/Table_Of_Contents]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 n xx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w1 rk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w20 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w5 su]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w6 pp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w4 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w7 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w8 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w9 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w10 pk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w12 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w14 gv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w17 ir]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w22 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w21 wi]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w31 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w16 br]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1a 1w23 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w24 nr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w15 rt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w3 pl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w32 cm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w37 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w67 ks]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w27 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w29 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w33 op]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w19 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w34 vd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w35 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1 1w30 rp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w58 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w47 sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w69 mv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w44 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w45 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w53 kc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 ar]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w39 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w54 go]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w56 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w64 nn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w66 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w40 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w42 js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w46 sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w71 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w63 dv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w55 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w57 mp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w52 an]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch1b 1w38 nm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w60 ac]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 1w62 rb]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w29 st]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w3_sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w30 an]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w17 pt]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w31 up]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w9 ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w19 is]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w26 aj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w5 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w16 dp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w8 vp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w18 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w3 jm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w23 sr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w11_aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w15 rr]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2a 2w33 pv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w20_aa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w14_bb]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w21_ap]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w13_sm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w4_sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w25_nr]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w12_sv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w7_ma]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w6_ar]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w32_mk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2a_2w10_rc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w70_sm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w67_sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w40_sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w22_sk]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w-1w65_am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w59_bc]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w60_ns]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b 2w47 am]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w69_as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w39_ka]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w36_av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w37_ms]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w43_iv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w53_iv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w63_sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w49_ps]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w52_sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w28_dh]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch1b 2w41 dc]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_1w59_nm]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_1w61_ps]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_2w57]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_2w42_aa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_1w61_ns]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_2w51_aa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2012/ch2b_2w45_pg]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_2w48_aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b_1w70_nl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2012/ch2b 2w64 bg]]&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65181</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65181"/>
		<updated>2012-09-18T15:07:04Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Multiple method definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
A Mixin is a class that is mixed with a [http://www.tutorialspoint.com/ruby/ruby_modules.htm module] or a set of modules i.e. the implementation of the modules and the class are intertwined and combined together &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
This gives us a neat and controlled way of adding new functionality to classes. [http://blog.rubybestpractices.com/posts/gregory/037-issue-8-uses-for-modules.html Modules] are similar to classes in that they hold a collection of methods, variables constants and other modules and class definitions. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. [http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html Interfaces] cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is mixed in where some modules have overloaded methods, the method from the module that was last mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces are similar in the fact that they enable additional features in object-oriented programming languages. They are dissimilar in the way they are implemented but add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;br /&gt;
6. Lucas Carlson; Leonard Richardson (July 2006), [http://shop.oreilly.com/product/9780596523695.do Ruby Cookbook], O'Reilly Media,  ISBN 10:0-596-52369-6&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65180</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65180"/>
		<updated>2012-09-18T15:05:50Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
A Mixin is a class that is mixed with a [http://www.tutorialspoint.com/ruby/ruby_modules.htm module] or a set of modules i.e. the implementation of the modules and the class are intertwined and combined together &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
This gives us a neat and controlled way of adding new functionality to classes. [http://blog.rubybestpractices.com/posts/gregory/037-issue-8-uses-for-modules.html Modules] are similar to classes in that they hold a collection of methods, variables constants and other modules and class definitions. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. [http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html Interfaces] cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces are similar in the fact that they enable additional features in object-oriented programming languages. They are dissimilar in the way they are implemented but add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;br /&gt;
6. Lucas Carlson; Leonard Richardson (July 2006), [http://shop.oreilly.com/product/9780596523695.do Ruby Cookbook], O'Reilly Media,  ISBN 10:0-596-52369-6&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65179</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65179"/>
		<updated>2012-09-18T15:00:54Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Interfaces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
A Mixin is a class that is mixed with a [http://www.tutorialspoint.com/ruby/ruby_modules.htm module] or a set of modules i.e. the implementation of the modules and the class are intertwined and combined together &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
This gives us a neat and controlled way of adding new functionality to classes. [http://blog.rubybestpractices.com/posts/gregory/037-issue-8-uses-for-modules.html Modules] are similar to classes in that they hold a collection of methods, variables constants and other modules and class definitions. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. [http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html Interfaces] cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces are similar in the fact that they enable multiple inheritance in programming languages that do not support multiple inheritance. They are dissimilar in the way they are implemented but add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;br /&gt;
6. Lucas Carlson; Leonard Richardson (July 2006), [http://shop.oreilly.com/product/9780596523695.do Ruby Cookbook], O'Reilly Media,  ISBN 10:0-596-52369-6&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65178</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65178"/>
		<updated>2012-09-18T15:00:01Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Interfaces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
A Mixin is a class that is mixed with a [http://www.tutorialspoint.com/ruby/ruby_modules.htm module] or a set of modules i.e. the implementation of the modules and the class are intertwined and combined together &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
This gives us a neat and controlled way of adding new functionality to classes. [http://blog.rubybestpractices.com/posts/gregory/037-issue-8-uses-for-modules.html Modules] are similar to classes in that they hold a collection of methods, variables constants and other modules and class definitions. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. [http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html Interfaces] cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces are similar in the fact that they enable multiple inheritance in programming languages that do not support multiple inheritance. They are dissimilar in the way they are implemented but add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;br /&gt;
6. Lucas Carlson; Leonard Richardson (July 2006), [http://shop.oreilly.com/product/9780596523695.do Ruby Cookbook], O'Reilly Media,  ISBN 10:0-596-52369-6&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65177</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65177"/>
		<updated>2012-09-18T14:56:14Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Mixins */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
A Mixin is a class that is mixed with a [http://www.tutorialspoint.com/ruby/ruby_modules.htm module] or a set of modules i.e. the implementation of the modules and the class are intertwined and combined together &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
This gives us a neat and controlled way of adding new functionality to classes. [http://blog.rubybestpractices.com/posts/gregory/037-issue-8-uses-for-modules.html Modules] are similar to classes in that they hold a collection of methods, variables constants and other modules and class definitions. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces are similar in the fact that they enable multiple inheritance in programming languages that do not support multiple inheritance. They are dissimilar in the way they are implemented but add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;br /&gt;
6. Lucas Carlson; Leonard Richardson (July 2006), [http://shop.oreilly.com/product/9780596523695.do Ruby Cookbook], O'Reilly Media,  ISBN 10:0-596-52369-6&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65176</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65176"/>
		<updated>2012-09-18T14:53:49Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Mixins */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
A Mixin is a class that is mixed with a [http://www.tutorialspoint.com/ruby/ruby_modules.htm module] or a set of modules i.e. the implementation of the modules and the class are intertwined and combined together &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces are similar in the fact that they enable multiple inheritance in programming languages that do not support multiple inheritance. They are dissimilar in the way they are implemented but add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;br /&gt;
6. Lucas Carlson; Leonard Richardson (July 2006), [http://shop.oreilly.com/product/9780596523695.do Ruby Cookbook], O'Reilly Media,  ISBN 10:0-596-52369-6&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65175</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=65175"/>
		<updated>2012-09-18T14:45:35Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces are similar in the fact that they enable multiple inheritance in programming languages that do not support multiple inheritance. They are dissimilar in the way they are implemented but add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;br /&gt;
6. Lucas Carlson; Leonard Richardson (July 2006), [http://shop.oreilly.com/product/9780596523695.do Ruby Cookbook], O'Reilly Media,  ISBN 10:0-596-52369-6&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=64028</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=64028"/>
		<updated>2012-09-13T15:12:38Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* See Also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;br /&gt;
6. Lucas Carlson; Leonard Richardson (July 2006), [http://shop.oreilly.com/product/9780596523695.do Ruby Cookbook], O'Reilly Media,  ISBN 10:0-596-52369-6&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63808</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63808"/>
		<updated>2012-09-13T00:42:27Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Multiple method definitions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definition====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63807</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63807"/>
		<updated>2012-09-13T00:41:42Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Inheritance: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63806</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63806"/>
		<updated>2012-09-13T00:41:28Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Multiple object behavior: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63805</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63805"/>
		<updated>2012-09-13T00:41:16Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Multiple method definitions: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63804</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63804"/>
		<updated>2012-09-13T00:40:53Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63803</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63803"/>
		<updated>2012-09-13T00:40:39Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Overview===&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63802</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63802"/>
		<updated>2012-09-13T00:38:16Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Inheritance: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63801</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63801"/>
		<updated>2012-09-13T00:38:00Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Inheritance: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63800</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63800"/>
		<updated>2012-09-13T00:37:45Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Inheritance: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces whereas Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63799</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63799"/>
		<updated>2012-09-13T00:36:38Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Multiple method definitions: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63797</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63797"/>
		<updated>2012-09-13T00:35:05Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Multiple method definitions: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have [http://en.wikipedia.org/wiki/Function_overloading overloaded methods], the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63796</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63796"/>
		<updated>2012-09-13T00:34:01Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Mixins */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63795</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63795"/>
		<updated>2012-09-13T00:33:40Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Mixins */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63793</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63793"/>
		<updated>2012-09-13T00:30:23Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Mixins */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the [http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't repeat yourself] principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63792</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63792"/>
		<updated>2012-09-13T00:28:29Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an [http://en.wikipedia.org/wiki/Abstract_type abstract] class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63791</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63791"/>
		<updated>2012-09-13T00:27:16Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in [http://en.wikipedia.org/wiki/Java_(programming_language) Java] programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63789</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63789"/>
		<updated>2012-09-13T00:26:05Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are [http://en.wikipedia.org/wiki/Ruby_(programming_language) Ruby] modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in Java programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63787</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63787"/>
		<updated>2012-09-13T00:21:44Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are Ruby modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in Java programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. They add more flexibility to object-oriented programming and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63786</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63786"/>
		<updated>2012-09-13T00:20:17Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Drawbacks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are Ruby modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in Java programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding refers to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. However, they have their own disadvantages. Modules add more flexibility to object-oriented programming by the use of DRY principle and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63785</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63785"/>
		<updated>2012-09-13T00:20:05Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Drawbacks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are Ruby modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in Java programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to remember the hierarchy is difficult. Mixins suffer from silent method overriding. Silent method overriding referes to a condition when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. However, they have their own disadvantages. Modules add more flexibility to object-oriented programming by the use of DRY principle and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63783</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63783"/>
		<updated>2012-09-13T00:17:01Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Other Comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are Ruby modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in Java programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code and also help us solve the diamond problem, they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to keep in mind the hierarchy is practically impossible. Another issue associated with Mixins pose is silent method overriding. Silent method overriding occurs when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. However, they have their own disadvantages. Modules add more flexibility to object-oriented programming by the use of DRY principle and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63782</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63782"/>
		<updated>2012-09-13T00:16:28Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Tabular Comparison */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are Ruby modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in Java programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Other Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain method definitions. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code and also help us solve the diamond problem, they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to keep in mind the hierarchy is practically impossible. Another issue associated with Mixins pose is silent method overriding. Silent method overriding occurs when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. However, they have their own disadvantages. Modules add more flexibility to object-oriented programming by the use of DRY principle and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63780</id>
		<title>CSC/ECE 517 Fall 2012/ch1a 1w16 br</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2012/ch1a_1w16_br&amp;diff=63780"/>
		<updated>2012-09-13T00:13:53Z</updated>

		<summary type="html">&lt;p&gt;Bsampat2: /* Achieving Multiple Inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Overview==&lt;br /&gt;
&lt;br /&gt;
Mixins are Ruby modules. A module is a grouping of objects under a single name. The objects may be constants, methods, classes, or other modules. Modules are defined in Ruby using the keyword module. They can be incorporated into a class with Ruby’s include statement. This is called a mixin.&lt;br /&gt;
Modules are for sharing behavior (methods), while classes are for modeling relationship between objects. Ruby classes can Mixin a module and receive all its methods for free.&lt;br /&gt;
An Interface in Java programming language is an abstract type that classes must implement. Interfaces are declared using the interface keyword, and may only contain method signature and constant declarations.&lt;br /&gt;
A class that implements an interface must implement all of the methods described in the interface, or be an abstract class.&lt;br /&gt;
&lt;br /&gt;
==Definitions==&lt;br /&gt;
===Mixins===&lt;br /&gt;
	Modules provide a structure to collect classes, methods, and constants into a single, separately defined unit. They provide the simplest and an elegant way to adhere to the Don't repeat yourself&amp;lt;ref&amp;gt;[http://en.wikipedia.org/wiki/Don't_repeat_yourself Don't_repeat_yourself]&amp;lt;/ref&amp;gt; principle. This is useful so as to avoid clashes with existing classes, methods, and constants.&lt;br /&gt;
Modules are defined in Ruby using the module keyword.&lt;br /&gt;
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 &amp;lt;ref&amp;gt;[http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Mixins] &amp;lt;/ref&amp;gt;.&lt;br /&gt;
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. However, 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.&lt;br /&gt;
Below is an example for modules and Mixins:&lt;br /&gt;
The module ParkingSlot consists of the methods park and unpark&lt;br /&gt;
 &lt;br /&gt;
 module ParkingSlot&lt;br /&gt;
       def park&lt;br /&gt;
          #code to park the car&lt;br /&gt;
       end&lt;br /&gt;
       def unpark&lt;br /&gt;
          #code to unpark the car&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
The module ParkingMeter consists of the methods calculate and printreceipt&lt;br /&gt;
&lt;br /&gt;
 module ParkingMeter&lt;br /&gt;
       def calculate&lt;br /&gt;
          #code to calculate the parking fee&lt;br /&gt;
       end&lt;br /&gt;
       def printreceipt&lt;br /&gt;
          #code to print the receipt&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
When a class includes a module via include Module Name, all the methods on that module become instance methods on the class.&lt;br /&gt;
&lt;br /&gt;
 class Parking&lt;br /&gt;
      include ParkingSlot&lt;br /&gt;
      include ParkingMeter&lt;br /&gt;
      def printcardetails&lt;br /&gt;
          #code to print the details and type of car&lt;br /&gt;
      end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
The modules ParkingSlot and ParkingMeter are “included” in the Parking class. All the variables and the instance methods of the modules ParkingSlot and ParkingMeter are now said to be “mixed in” into the class. It is now possible for class instances to use these methods defined in the modules as and when required.&lt;br /&gt;
 p=Parking.new   &lt;br /&gt;
 p.park            # -&amp;gt; Method park from module ParkingSlot&lt;br /&gt;
 p.unpark          # -&amp;gt; Method unpark from module ParkingSlot&lt;br /&gt;
 p.calculate       # -&amp;gt; Method calculate from module ParkingMeter&lt;br /&gt;
 p.printreceipt    # -&amp;gt; Method printreceipt from module ParkingMeter&lt;br /&gt;
 p.printcardetails # -&amp;gt; Calls printCarDetails from class&lt;br /&gt;
The class Parking inherits from both the modules and the module methods are now available in Parking. Hence, it is now possible to use the methods with an instance of the Parking class p.&lt;br /&gt;
Hence, Mixins can be thought of taking different methods and variables defined in different modules making them available as instance methods in the class as well, thereby extending the class’ functionality. Effectively mixed in modules behave as superclass. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:ParkingLot.PNG| center]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interfaces===&lt;br /&gt;
In an object-oriented programming languages such as Java, C#, an interface&amp;lt;ref&amp;gt;[http://download.oracle.com/javase/tutorial/ Interfaces] &amp;lt;/ref&amp;gt; is a reference type, similar to a class that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated and they can only be implemented by classes or extended by other interfaces. All methods are public by default and any fields declared in an interface are by default static and final.&lt;br /&gt;
Example:&lt;br /&gt;
 public interface ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot);&lt;br /&gt;
       boolean remove(Car car);&lt;br /&gt;
       boolean findCar(Int number);&lt;br /&gt;
       int freeSlotsCount();&lt;br /&gt;
       int occupiedSlots();&lt;br /&gt;
       int parkingType();&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration);&lt;br /&gt;
       int findParkingSlot();&lt;br /&gt;
 }&lt;br /&gt;
 public class Mall implements ParkingLot {&lt;br /&gt;
       boolean add(Car car, int slot) { //... Code to add a car into the parking lot... }&lt;br /&gt;
       boolean remove(Car car){ // do something }&lt;br /&gt;
       boolean findCar(Int number){ // do something }&lt;br /&gt;
       int freeSlotsCount(){ // do something }&lt;br /&gt;
       int occupiedSlots(){ // do something }&lt;br /&gt;
       int parkingType(){ // do something }&lt;br /&gt;
       int calculateParkingFee(int hours, int charge, int duration){ // do something }&lt;br /&gt;
       int findParkingSlot(){ // do something }&lt;br /&gt;
 }&lt;br /&gt;
Interfaces play another important role in the object-oriented programming language. Interfaces are not part of the class hierarchy, although they work in combination with classes.&lt;br /&gt;
&lt;br /&gt;
==Mixins vs. Interfaces==&lt;br /&gt;
===Similarities and Differences===&lt;br /&gt;
	Mixins and Interfaces can be considered as a block of code having some variables and methods that can be used by a class. The difference between them is that a Mixin can contain method definitions whereas an Interface cannot.&lt;br /&gt;
&lt;br /&gt;
====Multiple method definitions:====&lt;br /&gt;
	In a class, when more than one module is Mixed in where some modules have overloaded methods, the method from the module that was last Mixed in into the class will be executed.&lt;br /&gt;
 module Frog&lt;br /&gt;
    def sound()&lt;br /&gt;
      puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
     end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
   def sound()&lt;br /&gt;
     puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
       include Frog&lt;br /&gt;
       include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Frogosaur.new.sound &amp;lt;br&amp;gt;	&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 roar...&amp;lt;br&amp;gt;&lt;br /&gt;
This is because the class Frogosaur can contain only one definition for each method. The users have the flexibility to make use of methods from different modules by rearranging the order of include.&lt;br /&gt;
Interfaces, on the other hand, do not offer the flexibility to have different implementation for a same method. This is because the class implementing the interface can provide only one implementation for each method. Hence they offer only one method definition for the user.&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void sound();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
 public void sound()&lt;br /&gt;
 {&lt;br /&gt;
     System.out.println(&amp;quot;barks......&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public static void main(String args[])&lt;br /&gt;
 {&lt;br /&gt;
     new Frogosaur().sound();;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Multiple object behavior:====&lt;br /&gt;
In Ruby, a class’s instance can extend a module and exhibit different behavior than the other instances of the same class.&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
  def sound()&lt;br /&gt;
     puts &amp;quot;croak...&amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 module Dinasour&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;roar...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
  def sound()&lt;br /&gt;
    puts &amp;quot;barks...&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 beast1= Frogosaur.new&lt;br /&gt;
 beast2= Frogosaur.new&lt;br /&gt;
 beast1.extend(Frog)&lt;br /&gt;
 beast1.sound&lt;br /&gt;
 beast2.sound&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 croak...&amp;lt;br&amp;gt;&lt;br /&gt;
 barks...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Interfaces are implemented by a class and all instances of the class behave in the same way. They can only use the methods of the class to which they belong to.&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  public void sound()&lt;br /&gt;
  {&lt;br /&gt;
      System.out.println(&amp;quot;Sounds...&amp;quot;);&lt;br /&gt;
  }  &lt;br /&gt;
  public static void main(String args[])&lt;br /&gt;
  {&lt;br /&gt;
      Frogosaur beast1 = new Frogosaur();&lt;br /&gt;
      Frogosaur beast2 = new Frogosaur();&lt;br /&gt;
      object1.sound();&lt;br /&gt;
      object2.sound();&lt;br /&gt;
  }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
 Sounds...&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enumerable – module and interface====&lt;br /&gt;
&lt;br /&gt;
Ruby’s Arrays have several methods defined in them. To use them, the classes need not be a subclass of Array. The classes can include Enumerable &amp;lt;ref&amp;gt;[http://mattenoble.com/2011/05/30/ruby-enumerables/ Enumerables]&amp;lt;/ref&amp;gt; and define the each method to use the array’s methods for free.&lt;br /&gt;
&lt;br /&gt;
 class EnumExer&lt;br /&gt;
  include Enumerable&lt;br /&gt;
  def initialize(*arrays)&lt;br /&gt;
    @arrays = arrays&lt;br /&gt;
  end&lt;br /&gt;
  def each&lt;br /&gt;
    @arrays.each { |a| a.each { |x| yield x } }&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
 ma = EnumExer.new([4, 1], [3], [2])&lt;br /&gt;
 puts ma.sort&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 1&amp;lt;br&amp;gt;&lt;br /&gt;
 2&amp;lt;br&amp;gt;&lt;br /&gt;
 3&amp;lt;br&amp;gt;&lt;br /&gt;
 4&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can observe that although the arguments passed to the ma instance did not have a similar structure, the sort method was able to identify each entry and sort them. This is because the each method was defined to identify and serve all the entries to the sort method.&lt;br /&gt;
The methods that are defined for Enumerable modules are:&lt;br /&gt;
 [&amp;quot;all?&amp;quot;, &amp;quot;any?&amp;quot;, &amp;quot;collect&amp;quot;, &amp;quot;detect&amp;quot;, &amp;quot;each_with_index&amp;quot;, &amp;quot;entries&amp;quot;,&amp;quot;find&amp;quot;, &amp;quot;find_all&amp;quot;, &amp;quot;grep&amp;quot;, &amp;quot;include?&amp;quot;, &amp;quot;inject&amp;quot;,&lt;br /&gt;
 &amp;quot;map&amp;quot;, &amp;quot;max&amp;quot;,&amp;quot;member?&amp;quot;, &amp;quot;min&amp;quot;, &amp;quot;partition&amp;quot;, &amp;quot;reject&amp;quot;, &amp;quot;select&amp;quot;, &amp;quot;sort&amp;quot;, &amp;quot;sort_by&amp;quot;,&amp;quot;to_a&amp;quot;, &amp;quot;zip&amp;quot;]&lt;br /&gt;
In Java, to use the methods of Enumerable interface, the class should be a subclass of Array.&lt;br /&gt;
&lt;br /&gt;
 public class EnumExer {&lt;br /&gt;
     static String content_string = &amp;quot;zyxwvutsrqponmlkjihgfedcba&amp;quot;;&lt;br /&gt;
     String a=&amp;quot;1&amp;quot;, b=&amp;quot;2&amp;quot;;&lt;br /&gt;
     public static void main(String args[])&lt;br /&gt;
     {&lt;br /&gt;
         char[] content_array = content_string.toCharArray();&lt;br /&gt;
         java.util.Arrays.sort(content_array);&lt;br /&gt;
         content_string=new String(content_array);&lt;br /&gt;
         System.out.println(content_string);&lt;br /&gt;
     }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 '''Output:'''&amp;lt;br&amp;gt;&lt;br /&gt;
 Abcdefghijklmnopqrstuvwxyz&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the string object was converted to a character array to be able to use with the sort method.&lt;br /&gt;
&lt;br /&gt;
====Inheritance:====&lt;br /&gt;
Java interfaces can inherit other interfaces but Ruby modules cannot inherit other modules although they can contain classes and methods.&lt;br /&gt;
 module Wrapper&lt;br /&gt;
  class Base&lt;br /&gt;
     # Class Body&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Dinasour extends Frog{&lt;br /&gt;
     //variables and method Declarations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==== Achieving Multiple Inheritance ====&lt;br /&gt;
Modules and Interfaces help acheive multiple inheritance.  &amp;lt;br&amp;gt;&lt;br /&gt;
Interfaces are used in Java to achieve multiple inheritance&amp;lt;ref&amp;gt; [http://csis.pace.edu/~bergin/patterns/multipleinheritance.html  Mulitple Inheritance] &amp;lt;/ref&amp;gt;. Similarly, modules in Ruby help achieve multiple inheritance.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Ruby,&lt;br /&gt;
&lt;br /&gt;
 module Frog&lt;br /&gt;
   def jump()&lt;br /&gt;
     //Method definition&lt;br /&gt;
    end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 module Dinosaur&lt;br /&gt;
  def strength()&lt;br /&gt;
    //Method definition&lt;br /&gt;
  end&lt;br /&gt;
 end &amp;lt;br&amp;gt;&lt;br /&gt;
 class Frogosaur&lt;br /&gt;
      include Frog&lt;br /&gt;
      include Dinosaur&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
In Java,&lt;br /&gt;
 public interface Frog {&lt;br /&gt;
     void jump();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public interface Dinasour {&lt;br /&gt;
     void strength();&lt;br /&gt;
 } &amp;lt;br&amp;gt;&lt;br /&gt;
 public class Frogosaur implements Frog,Dinasour{&lt;br /&gt;
  //Method Implementations&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Frogosaur inherits the methods of both frog and dinosaur.&lt;br /&gt;
&lt;br /&gt;
===Tabular Comparison===&lt;br /&gt;
{|border=&amp;quot;2&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot; align=&amp;quot;center&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Mixins&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Interfaces&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|The number of lines of code is lesser since the &amp;lt;br&amp;gt;&lt;br /&gt;
modules contain the method definition. &lt;br /&gt;
|The number of lines of code is bigger since the &amp;lt;br&amp;gt;&lt;br /&gt;
classes have to define the methods.&lt;br /&gt;
|-&lt;br /&gt;
|More modules in a class makes code less readable.&lt;br /&gt;
|The code is more readable since the class contain the &amp;lt;br&amp;gt;&lt;br /&gt;
method definition.&lt;br /&gt;
|-&lt;br /&gt;
|Modules cannot be inherited and cannot form is-a hierarchy.&lt;br /&gt;
|Interfaces can extend another interface and hence can form &amp;lt;br&amp;gt;&lt;br /&gt;
is-a hierarchy.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Drawbacks===&lt;br /&gt;
The drawbacks of the technique of Mixins are very much debated. Though Mixins provide us with an easy way to write flexible and decoupled code and also help us solve the diamond problem, they pose their own problems. In large programs there could be large number of modules and each module could have loads of methods each performing a certain task. To trace the origin of the methods and to keep in mind the hierarchy is practically impossible. Another issue associated with Mixins pose is silent method overriding. Silent method overriding occurs when different modules are included in a class and each module have a method with the same definition. In such a case, the method which gets executed depends upon the way it is included in the class and this is done without any sort of message to the user (silently). In large scale applications this could certainly be an issue considering the number of modules that would be mixed in and it would be difficult to keep track of the hierarchy in which the modules were included.&lt;br /&gt;
Although Java provides polymorphic behavior with the use of interfaces, they sometimes tend to be very slow. The implementation of interfaces is also limited to public methods and constants with no implementation.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
Modules and Interfaces offer many advantages. However, they have their own disadvantages. Modules add more flexibility to object-oriented programming by the use of DRY principle and are easy to maintain.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
1. http://ruby.about.com/od/beginningruby/a/mixin.htm/ &amp;lt;br&amp;gt;&lt;br /&gt;
2. http://juixe.com/techknow/index.php/2006/06/15/mixins-in-ruby/ &amp;lt;br&amp;gt;&lt;br /&gt;
3. http://www.innovationontherun.com/why-rubys-mixins-gives-rails-an-advantage-over-java-frameworks/ &amp;lt;br&amp;gt;&lt;br /&gt;
4. http://pg-server.csc.ncsu.edu/mediawiki/index.php?title=CSC/ECE_517_Fall_2010/ch3_3b_sv&amp;amp;printable=yes &amp;lt;br&amp;gt;&lt;br /&gt;
5. http://expertiza.csc.ncsu.edu/wiki/index.php/CSC/ECE_517_Fall_2011/ch2_2c_ds &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bsampat2</name></author>
	</entry>
</feed>