<?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=Abalasu3</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=Abalasu3"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Abalasu3"/>
	<updated>2026-08-10T21:59:49Z</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_2011/ch4_4a_aj&amp;diff=53449</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53449"/>
		<updated>2011-10-21T00:07:39Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* When &amp;quot;extends&amp;quot; is more useful than Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object.&amp;lt;/p&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 [http://docs.selflanguage.org/langref.html slots].   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language.&lt;br /&gt;
Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;br /&gt;
&lt;br /&gt;
[http://docs.selflanguage.org/langref.html Slots]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53443</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53443"/>
		<updated>2011-10-21T00:05:59Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object.&amp;lt;/p&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 [http://docs.selflanguage.org/langref.html slots].   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &amp;lt;/p&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;br /&gt;
&lt;br /&gt;
[http://docs.selflanguage.org/langref.html Slots]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53438</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53438"/>
		<updated>2011-10-21T00:03:41Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object.&amp;lt;/p&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 [http://docs.selflanguage.org/langref.html slots].   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &amp;lt;/p&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;br /&gt;
&lt;br /&gt;
[http://docs.selflanguage.org/langref.html Slots]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53436</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53436"/>
		<updated>2011-10-21T00:03:18Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object.&amp;lt;/p&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 [http://docs.selflanguage.org/langref.html slots].   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &amp;lt;/p&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53435</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53435"/>
		<updated>2011-10-21T00:00:40Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object.&amp;lt;/p&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &amp;lt;/p&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53434</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53434"/>
		<updated>2011-10-21T00:00:10Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* When &amp;quot;extends&amp;quot; is more useful than Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &amp;lt;/p&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53433</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53433"/>
		<updated>2011-10-20T23:59:48Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* When &amp;quot;extends&amp;quot; is more useful than Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;&lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53430</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53430"/>
		<updated>2011-10-20T23:59:26Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* When &amp;quot;extends&amp;quot; is more useful than Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &amp;lt;p&amp;gt;&lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53428</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53428"/>
		<updated>2011-10-20T23:59:02Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* When &amp;quot;extends&amp;quot; is more useful than Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &amp;lt;br&amp;gt;&lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53423</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53423"/>
		<updated>2011-10-20T23:58:09Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* When &amp;quot;extends&amp;quot; is better than Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is more useful than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53422</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53422"/>
		<updated>2011-10-20T23:57:55Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Cloning_(programming) Cloning]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53421</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53421"/>
		<updated>2011-10-20T23:57:29Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Prototype based Languages in Brief */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53418</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53418"/>
		<updated>2011-10-20T23:56:27Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Self_(programming_language) Self Programming]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53407</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53407"/>
		<updated>2011-10-20T23:51:37Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Prototype based Languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages in Brief''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53406</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53406"/>
		<updated>2011-10-20T23:51:10Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53399</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53399"/>
		<updated>2011-10-20T23:49:19Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Implementation of Code Reuse: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as [http://en.wikipedia.org/wiki/Multiple_inheritance Multiple Inheritance].&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53395</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53395"/>
		<updated>2011-10-20T23:47:53Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://ruby-doc.org/docs/ProgrammingRuby/html/classes.html Extends in Ruby]&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly What makes Ruby Powerful?]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://docs.python.org/tutorial/classes.html Inheritance in Python]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53382</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53382"/>
		<updated>2011-10-20T23:43:15Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance in General]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Prototype-based_programming Prototype based Programming]&lt;br /&gt;
&lt;br /&gt;
[http://coweb.cc.gatech.edu]&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53381</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53381"/>
		<updated>2011-10-20T23:42:24Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://www.tenouk.com/Module14.html Inheritance in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly Extends in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://helephant.com/2009/08/17/javascript-prototype-chaining Java Script Prototype Chaining]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53377</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53377"/>
		<updated>2011-10-20T23:40:35Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx Extends in C#]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53376</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53376"/>
		<updated>2011-10-20T23:40:17Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[http://msdn.microsoft.com/en-us/library/bb383977.aspx]&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53375</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53375"/>
		<updated>2011-10-20T23:39:45Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html Extends in Java]&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53374</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53374"/>
		<updated>2011-10-20T23:39:16Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[http://xahlee.org/java-a-day/extend.html]&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53372</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53372"/>
		<updated>2011-10-20T23:38:31Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* When extends are better than Cloning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When &amp;quot;extends&amp;quot; is better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53370</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53370"/>
		<updated>2011-10-20T23:38:00Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When extends are better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53368</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53368"/>
		<updated>2011-10-20T23:37:39Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
 ==''Prototype based Languages''==&lt;br /&gt;
&amp;lt;p&amp;gt;Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''Cloning''== &lt;br /&gt;
&amp;lt;p&amp;gt;We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
==''When extends are better than Cloning''==&lt;br /&gt;
 &amp;lt;p&amp;gt;Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53364</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=53364"/>
		<updated>2011-10-20T23:35:52Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype Based languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;==''Prototype based Languages''==&lt;br /&gt;
Prototype-based programming is a kind of object-oriented programming in which there are no classes, and behavior&lt;br /&gt;
 reuse is performed through the process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;==''Cloning''== &lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C#, and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;==''When extends are better than Cloning''==&lt;br /&gt;
 Just like any other style, Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]]http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[7]]]http://en.wikipedia.org/wiki/Prototype-based_programming&lt;br /&gt;
&lt;br /&gt;
[[#References|[8]]]http://coweb.cc.gatech.edu&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52818</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52818"/>
		<updated>2011-10-20T00:59:33Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;br /&gt;
&lt;br /&gt;
[[#References|[6]]] http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52817</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52817"/>
		<updated>2011-10-20T00:58:15Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Implementation of Code Reuse: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;[http://en.wikipedia.org/wiki/Inheritance_in_object-oriented_programming Inheritance] is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or multiple classes, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52816</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52816"/>
		<updated>2011-10-20T00:51:00Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52815</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52815"/>
		<updated>2011-10-20T00:50:13Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of Extend methods in Java, C# and Ruby. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52814</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52814"/>
		<updated>2011-10-20T00:49:51Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of Extend methods in Java, C# and Ruby. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''In C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52813</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52813"/>
		<updated>2011-10-20T00:49:19Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* In java: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''Java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''In C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''In C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''In Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''In Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52812</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52812"/>
		<updated>2011-10-20T00:49:03Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of Extend methods in Java, C# and Ruby. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''In java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''In C#:'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''In C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''In Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''In Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52811</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52811"/>
		<updated>2011-10-20T00:48:42Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of Extend methods in Java, C# and Ruby. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''In java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''''In C++'''''==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''In Python:'''''==&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''''In Ruby:'''''==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52810</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52810"/>
		<updated>2011-10-20T00:47:59Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of Extend methods in Java, C# and Ruby. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
=='''''In java:'''''==&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52809</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52809"/>
		<updated>2011-10-20T00:47:18Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52808</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52808"/>
		<updated>2011-10-20T00:46:38Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* How Extending Objects in Ruby is more powerful than other languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;p&amp;gt;  The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52807</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52807"/>
		<updated>2011-10-20T00:46:20Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of Extend methods in Java, C# and Ruby. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
    The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52806</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52806"/>
		<updated>2011-10-20T00:45:49Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of Extend methods in Java, C# and Ruby. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
    The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52805</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52805"/>
		<updated>2011-10-20T00:45:19Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison of Extend methods in Java, C# and Ruby. */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;p&amp;gt;A class declaration can use the extend keyword on another class as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;  The above example shows how to call the standard query operator OrderBy method on an array of integers.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;p&amp;gt;If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
    The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52803</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52803"/>
		<updated>2011-10-20T00:43:58Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Implementation of Code Reuse: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 &amp;lt;p&amp;gt;“Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 A class declaration can use the extend keyword on another class as follows:&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  The above example shows how to call the standard query operator OrderBy method on an array of integers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
 The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
    The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52802</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52802"/>
		<updated>2011-10-20T00:43:35Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;p&amp;gt; One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 “Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 A class declaration can use the extend keyword on another class as follows:&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  The above example shows how to call the standard query operator OrderBy method on an array of integers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
 The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
    The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52801</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52801"/>
		<updated>2011-10-20T00:42:16Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
     One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&lt;br /&gt;
	&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 “Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 A class declaration can use the extend keyword on another class as follows:&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
  The above example shows how to call the standard query operator OrderBy method on an array of integers.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&lt;br /&gt;
 To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&lt;br /&gt;
 The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
    The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52800</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52800"/>
		<updated>2011-10-20T00:39:59Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; '''''Extending objects.''''' : ''Consider one or more practical examples of Ruby's extend method--that is,&lt;br /&gt;
 examples that serve a real need and are not contrived.  What facilities do other languages have for extending&lt;br /&gt;
 objects?  Are they more or less powerful than Ruby's?  Also consider prototype-based languages such as Self, &lt;br /&gt;
 which don't even provide classes.''&lt;br /&gt;
---------------------------&lt;br /&gt;
= Introduction=&lt;br /&gt;
&lt;br /&gt;
     One of the most fundamental advantages of using Object Orientation is to reuse code. Rather than coding what was already &lt;br /&gt;
 coded, we can simply extend it to suit the needs of the new class. This helps to develop applications rapidly. &lt;br /&gt;
 Many languages provide built in libraries which can be included in classes. The O-O languages also provide a way to add&lt;br /&gt;
 functionality to existing classes through extension.&lt;br /&gt;
	&lt;br /&gt;
=Implementation of Code Reuse:=&lt;br /&gt;
	&lt;br /&gt;
 “Inheritance” is the word used in O-O for the process of inheriting the members of a class and extending the functionality. &lt;br /&gt;
 A class can inherit from a single class or “Multiple Classes”, the latter is called as “Multiple Inheritance”.&lt;br /&gt;
 While a child class inherits from the parent class,  it tends to inherit all the members of the class.&lt;br /&gt;
&lt;br /&gt;
=Comparison of Extend methods in Java, C# and Ruby.=&lt;br /&gt;
&lt;br /&gt;
'''''In java:'''''&lt;br /&gt;
 &lt;br /&gt;
 A class declaration can use the extend keyword on another class as follows:&lt;br /&gt;
&amp;lt;Code&amp;gt;&lt;br /&gt;
 Class Course extends College &lt;br /&gt;
 {&lt;br /&gt;
 ..............&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
 When a class Child extends class Parent, Child automatically has all variables and methods defined in class Parent.&lt;br /&gt;
 If class Child defines a variable or method that has the same name in class Parent, class Child's definition &lt;br /&gt;
 overrides that of Parent's.&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
 class Parent {&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; y=b; return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void Show(){&lt;br /&gt;
 System.out.println(x);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class Child extends Parent {&lt;br /&gt;
 public static void main(String args[]){&lt;br /&gt;
 Parent p = new Parent();&lt;br /&gt;
 p.get(5,6);&lt;br /&gt;
 p.Show();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display(){&lt;br /&gt;
 System.out.println(&amp;quot;Child&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''''In C#:'''''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Extension methods enable the programmer to &amp;quot;add&amp;quot; methods to existing types without creating a new derived type, recompiling, &lt;br /&gt;
 or otherwise modifying    the original type. Extension methods are a special kind of static method, but they are called &lt;br /&gt;
 as if they were instance methods on the extended type. &lt;br /&gt;
&lt;br /&gt;
 class ExtensionMethod    &lt;br /&gt;
 {&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {            &lt;br /&gt;
        int[] s = { 1, 55, 75, 93, 81, 96 };&lt;br /&gt;
        var r = s.OrderBy(g =&amp;gt; g);&lt;br /&gt;
        foreach (var a in result)&lt;br /&gt;
        {&lt;br /&gt;
            System.Console.Write(a + &amp;quot; &amp;quot;);&lt;br /&gt;
        }           &lt;br /&gt;
    }        &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
  Output: &lt;br /&gt;
  1       55          15       81            93          96&lt;br /&gt;
  The above example shows how to call the standard query operator OrderBy method on an array of integers.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In C++'''''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Similar to Java, C++ also extends functionality of a base class to a derived class. The derived class can use the functions &lt;br /&gt;
 and variables of a base  class as well as add their own functionality, thus making them a more specialized version of the base &lt;br /&gt;
 class.  Similar to Java, overriding is also supported in C++. Here is an example of how a class is extended in C++.&lt;br /&gt;
&lt;br /&gt;
 class Base{&lt;br /&gt;
 public:&lt;br /&gt;
 int x;&lt;br /&gt;
 int y;&lt;br /&gt;
 int get(int a, int b){&lt;br /&gt;
 x=a; &lt;br /&gt;
 y=b; &lt;br /&gt;
 return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 void display()&lt;br /&gt;
 cout&amp;lt;&amp;lt;x&amp;lt;&amp;lt;y;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class derived:public base{&lt;br /&gt;
 void Main(){&lt;br /&gt;
 Base b;&lt;br /&gt;
 b.get(5,6);&lt;br /&gt;
 b.display();&lt;br /&gt;
 void display(){&lt;br /&gt;
 cout&amp;lt;&amp;lt;”Derived”;&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Python:'''''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 To extend a class in Python, we simply call the parent class in the parenthesis while defining the child class. &lt;br /&gt;
 This will pass all the methods and variables defined in the parent class to the child class.&lt;br /&gt;
 An illustration of how classes are extended in python.&lt;br /&gt;
&lt;br /&gt;
 class Parent:&lt;br /&gt;
 a=5&lt;br /&gt;
 b=4&lt;br /&gt;
 def add():&lt;br /&gt;
 print(a+b)&lt;br /&gt;
 class Child(Parent):&lt;br /&gt;
 def difference():&lt;br /&gt;
 print(a-b)&lt;br /&gt;
 p = Parent()&lt;br /&gt;
 c = Child()&lt;br /&gt;
 c.add()&lt;br /&gt;
 c.difference()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''''In Ruby:'''''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 The include method effectively adds a module as a super class of self. It is used inside a class definition &lt;br /&gt;
 to make the instance methods in the module available to instances of the class.&lt;br /&gt;
 It is sometimes useful to add the instance methods to a particular object.&lt;br /&gt;
 This is done using Object#extend.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not a pencil for your exam!&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 obj = &amp;quot; Proctor&amp;quot;&lt;br /&gt;
 obj.extend Write&lt;br /&gt;
 puts obj.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&lt;br /&gt;
 If the extend key word is used within a class definition, the modules methods become class methods. &lt;br /&gt;
 This is because extend is equal to self.extend, so  the methods are added to self, which in a class definition is the class itself.&lt;br /&gt;
&lt;br /&gt;
 module Write&lt;br /&gt;
 def pen&lt;br /&gt;
 &amp;quot;#{self} says use a pen not pencil for your exam&amp;quot;&lt;br /&gt;
 end&lt;br /&gt;
 end&lt;br /&gt;
 class Proctor&lt;br /&gt;
 extend Write &lt;br /&gt;
 end&lt;br /&gt;
 puts Proctor.pen&lt;br /&gt;
&lt;br /&gt;
 Output: Proctor says use a pen not pencil for your exam&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
=How Extending Objects in Ruby is more powerful than other languages=&lt;br /&gt;
   &lt;br /&gt;
    The one main disadvantage of inheriting from a class is that, we tend to inherit all of its members, most of which&lt;br /&gt;
 we may not use in our programs.  Ruby however gives us the option of extending only what we need. Several modules can &lt;br /&gt;
 be created and these modules can be extended at runtime. The extend keyword makes the module available to all instances&lt;br /&gt;
 of the class.  A class can simply extend the modules and uses it the way it wants on the move. This, however, does not &lt;br /&gt;
 change the objects original code. This is really a unique and powerful feature of Ruby.&lt;br /&gt;
&lt;br /&gt;
='''Comparison of &amp;quot;Extend property &amp;quot; in Prototype languages to Class Based Languages.'''=&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;pre&amp;gt;&lt;br /&gt;
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior&lt;br /&gt;
 reuse is performed via a process  of cloning (Cloning is the process of  making of an exact copy of an object) existing objects &lt;br /&gt;
 that serve as prototypes. Languages like Self, Newton Script, Slate, Ioke, Io are examples of a prototype language.&lt;br /&gt;
 Most class-based Object Oriented languages are based on Classes which can be described as defining the basic qualities and &lt;br /&gt;
 behaviors of objects and object instances which can be described as being manifestations of classes. &lt;br /&gt;
 In prototype-based languages like Self, the duality between classes and object instances is not needed. There is no need for &lt;br /&gt;
 having an instance of an object that is based on a class. For example, in Self  a copy of an existing object is made, and &lt;br /&gt;
 then changes are made to it. Basic objects that are used primarily to make copies are known as prototypes. When an existing &lt;br /&gt;
 object  proves to be an insufficient, a programmer can create a modified object with the expected behavior, and use that instead of &lt;br /&gt;
 the previous one.  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 We saw how the extend key word is used in Java, C# and in Ruby. In languages like Self, instead of having a class definition take up&lt;br /&gt;
 memory, and every instance take up memory, clones of objects generally take up a small amount memory. Every object just points to another object.&lt;br /&gt;
 So the fewer changes the programmer makes to a clone of an object, the fewer the amounts of new data need to be stored, and thus lesser amount &lt;br /&gt;
 of memory that a programmer needs to do a new clone. Prototype-based languages will help simplify the understanding of each object. &lt;br /&gt;
 It is also a fact that languages like Self,  make it easier to fix bugs in code. This is because prototype-based languages use the concept of &lt;br /&gt;
 slots.   We are referring to a method as slot because the programmer can change the functionality of any object, by changing a method alone.     &lt;br /&gt;
 When new code is placed into an object's slot the functionality of that object is changed. &lt;br /&gt;
 Another advantage is that the user interfaces also benefit from the use of prototype-based languages. User interfaces &lt;br /&gt;
 hold less amount of objects. Objects are created in interfaces for a specific purpose. Without creating many classes for many &lt;br /&gt;
 purposes, or creating just a few big ones, each of them with a number of methods for implementation, cloning objects is a proved &lt;br /&gt;
 easier solution.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 Prototype-based programming has its own disadvantages. Consider the cases when repetitive types of data is used like the ones in a database. &lt;br /&gt;
 Here   prototype-based programming would decrease efficiency of these applications. And also in this case, Class-based programming will be best&lt;br /&gt;
 and perhaps the only solution for these kinds of problems.&lt;br /&gt;
 We saw that in Java, inheritance is achieved using extends keyword. In Java Script, a prototype based language, Prototype chaining is used&lt;br /&gt;
 to build new types of objects based on existing ones.  The functionality is very similar to inheritance in a class based language. &lt;br /&gt;
 Constructor  functions have a property known as prototype. Adding properties and methods to the prototype property will also adds the&lt;br /&gt;
 method or property to all objects created by the constructor function. This prototype property is a mere javascript object such that it is&lt;br /&gt;
 possible to create a function’s prototype using another constructor function. When this is done, all of the properties and methods from &lt;br /&gt;
 the   constructor function’s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function &lt;br /&gt;
 that builds objects that are just an extended version of an existing one.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
[[#References|[1]]]http://xahlee.org/java-a-day/extend.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[2]]]http://msdn.microsoft.com/en-us/library/bb383977.aspx&lt;br /&gt;
&lt;br /&gt;
[[#References|[3]]]http://www.tenouk.com/Module14.html&lt;br /&gt;
&lt;br /&gt;
[[#References|[4]]]http://perfectionlabstips.wordpress.com/2008/11/19/how-to-extend-ruby-object-on-the-fly&lt;br /&gt;
&lt;br /&gt;
[[#References|[5]]]http://helephant.com/2009/08/17/javascript-prototype-chaining.&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52444</id>
		<title>CSC/ECE 517 Fall 2011/ch4 4a aj</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch4_4a_aj&amp;diff=52444"/>
		<updated>2011-10-18T15:22:19Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: Created page with &amp;quot;New page&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;New page&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_2b_rv&amp;diff=51621</id>
		<title>CSC/ECE 517 Fall 2011/ch1 2b rv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_2b_rv&amp;diff=51621"/>
		<updated>2011-10-01T00:05:30Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* C# */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Access Control in O-O Languages&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Access control=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In [http://en.wikipedia.org/wiki/Object-oriented_programming object oriented programming], access control refers to the control of visibility of data and methods. The main idea behind access control is to restrict access to certain parts of the code to external entities. Access control implements [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) encapsulation] by providing varying levels of access to code. The use of access control becomes necessary in any practical environment where selective access is a key criterion. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;For example, only the instructor can be allowed to modify grades of students but all students should be given access to retrieve and view their respective grades.&amp;lt;/p&amp;gt;  &lt;br /&gt;
&amp;lt;p&amp;gt;Access control in different object oriented languages and the underlying details will be covered in this topic.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview of Access Control Mechanisms=&lt;br /&gt;
&lt;br /&gt;
Each O-O language has a specific implementation of access control mechanisms. However, a plethora of the most widely used o-o languages share similar features while implementing access control. Access control mechanisms are applicable to class members like variables and functions. Some level of access control can be applied at the class level. The 3 basic types of access control implementation which is common to some [http://en.wikipedia.org/wiki/Static-typing_%28programming_languages%29#Static_and_dynamic_typing static and dynamic O-O languages] [like C++, C#, Java and Ruby] are &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Public''' : Methods or attributes that are declared to be public can be accessed from any class. This is the least restrictive access control method. For example, we may want everyone in a company to know the names of people working along with them. Thus public access is given to employee's name.&lt;br /&gt;
&lt;br /&gt;
'''Private''' : This mechanism makes the data or method to be visible only in the class in which it is declared. The support is not extended to sub classes. This is the most restrictive access control method. &lt;br /&gt;
In any application, methods which implement the core functionality or require administrator access are declared to be private thereby enforcing limited access. For example, only a manager can be given the authority to review an employee’s performance and award bonus and promotions. &lt;br /&gt;
&lt;br /&gt;
'''Protected''' : The use of protected access allows access of data and methods to be modified by members belonging to the same family. This means that this support is extended to subclasses. Protected access control can be used to support the single interface, multiple implementation concept i.e, [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inheritance]. &lt;br /&gt;
For example, a super class may have a protected method called ComputeArea(). We can have many subclasses like Triangle, Rectangle etc inherit the super class and override the method ComputeArea() to provide their own specific implementation. In a more practical scenario, a person might be allowed to view the medical history of immediate family members. However, people outside the family will not be allowed access to view this medical history. &lt;br /&gt;
&lt;br /&gt;
=Implementing Access Control=&lt;br /&gt;
&lt;br /&gt;
Programming languages implement access control in different ways. We present a few of the languages that use access control and show their implementation.&lt;br /&gt;
&lt;br /&gt;
=='''Java'''==&lt;br /&gt;
In Java, access control is achieved using the modifiers public, private and protected. If a class is not declared with any modifier, then the default access becomes package-private i.e, any object within the package should be able to access this class. &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;'''Public Keyword''' – Other classes can modify public fields unless its declared as [http://en.wikipedia.org/wiki/Final_%28Java%29 final]. The syntax for declaring a variable/method public is as follows &amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;public int x;&lt;br /&gt;
public void print_Hello()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example shown below, the variable studentName is public and hence can be accessed in another class Student2. Similarly, public methods like getName() etc become accessible by other classes. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''Private Keyword''' – This keyword makes the class members private. Private members can only be accessed from within the class. They are not visible even in subclasses. However, visibility and access of private members is extended to nested classes. The syntax for declaring a variable/method private is as follows&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;private String EmpID; &lt;br /&gt;
private void getEmpDetails() &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In the example code below, the method setID is declared to be private. Hence, it cannot be accessed in the subclass of the class Student.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Protected Keyword''' – This keyword when used before a class member makes that member visible to the elements residing in that class and its subclasses. The syntax for declaring a variable/method protected is as follows&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;protected int sides; &lt;br /&gt;
protected void setArea(int sides)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In the example code below, the method setName is declared as protected. Hence, it can be accessed in the subclass NewStudent.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Default access level/Package''' – When no specific access control keyword is given, then the method or variable becomes accessible to all classes under a particular package. In the following example, the integer “packageVar” becomes accessible to all classes included in the package ‘TestPackage1’. Hence, it can be modified in the class Student2.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
package TestPackage1  &lt;br /&gt;
public class Student {  &lt;br /&gt;
&lt;br /&gt;
	public String studentName;&lt;br /&gt;
	public int studentID;&lt;br /&gt;
	int packageVar;&lt;br /&gt;
&lt;br /&gt;
	public String getName() {&lt;br /&gt;
		return studentName;&lt;br /&gt;
	}&lt;br /&gt;
	public int getID() {&lt;br /&gt;
		return studentID;&lt;br /&gt;
	}&lt;br /&gt;
	protected void setName(String s) {&lt;br /&gt;
		studentName = s;&lt;br /&gt;
	}&lt;br /&gt;
	private void setID(int y) {&lt;br /&gt;
		studentID = y;&lt;br /&gt;
	}&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		Student Stu1 = new Student();&lt;br /&gt;
		Stu1.setName(&amp;quot;ABCD&amp;quot;);&lt;br /&gt;
		Stu1.setID(1230013);&lt;br /&gt;
		System.out.println(Stu1.getName() + Stu1.getID());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
public class NewStudent extends Student {	&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		NewStudent NewStu1 = new NewStudent();&lt;br /&gt;
		NewStu1.setName(&amp;quot;EFGH&amp;quot;); 		//Can be accessed &lt;br /&gt;
		NewStu1.setID(350);		// Cannot be accessed as setID is private&lt;br /&gt;
		System.out.println(NewStu1.getName());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
public class Student2 {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
                Student Stu2 = new Student();&lt;br /&gt;
                Stu2.studentName = &amp;quot;Mickey&amp;quot;;     //Public variable of another class can be accessed&lt;br /&gt;
                Stu2.packageVar = 5;             //Default access level&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''C++==&lt;br /&gt;
In C++, we have the three modifiers presented in the overview along with a special type of access control called [http://en.wikipedia.org/wiki/Friend_function friend]. The behavior of public, private and protected modifiers is similar to its Java counterparts. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Friend - A function or class can access the private and protected members of a class if it is declared as a friend of that class. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
{	int a,b;&lt;br /&gt;
	friend int canAccess(Number numb); // Declaring canAccess() to be a friend&lt;br /&gt;
public:&lt;br /&gt;
	int add(int,int);&lt;br /&gt;
protected:&lt;br /&gt;
	int diff(int,int);&lt;br /&gt;
private:&lt;br /&gt;
	int prod(int,int);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	int add(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		return a+b;&lt;br /&gt;
	}&lt;br /&gt;
	int diff(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		if (a&amp;gt;b)&lt;br /&gt;
		 return a-b;&lt;br /&gt;
		else&lt;br /&gt;
		 return b-a;&lt;br /&gt;
	}&lt;br /&gt;
	int prod(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		return a*b;&lt;br /&gt;
	}	&lt;br /&gt;
};&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
  	Number num;&lt;br /&gt;
	int a=10, b=20;	&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Sum =&amp;quot; &amp;lt;&amp;lt; num.add(a,b);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Difference =&amp;quot; &amp;lt;&amp;lt; num.diff(a,b);&lt;br /&gt;
	//cout &amp;lt;&amp;lt; &amp;quot;Product = &amp;quot; &amp;lt;&amp;lt; num.prod(a,b); // this will throw an error if the comments are removed&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Friend function&lt;br /&gt;
int canAccess(Number numb)&lt;br /&gt;
{&lt;br /&gt;
 cout&amp;lt;&amp;lt; &amp;quot;Product for a friend = &amp;quot; &amp;lt;&amp;lt; numb.prod(10,20)  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More about friend functions'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;If a class is declared as a friend in another class, the friend class can access all the private members of the class. This can also be limited in such a way that only few private members of the class can be accessed. By using friend functions or classes, we can provide a flexibility of letting a friend class access restricted members of a class and still keeping the restricted members closed for access by any other class. This will be useful in a few cases.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Ruby==&lt;br /&gt;
Ruby provides the three levels of access controls, private, public and protected with the default being public access. The behavior of public and protected access control is similar to other languages like C++ and Java. &lt;br /&gt;
&amp;lt;p&amp;gt;However, private methods can be called only within the context of the current object. Other object’s private method cannot be invoked. Private methods can be overridden by the sub-classes.In most cases, private methods are used to provide internal functionality to the class. So we need to use a cautious approach in using private methods. If they are overridden by the subclass, we tend to get unexpected behavior in the program.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Note''': Private methods cannot be called outside of the class. Private methods can be called only using the “send” method. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
  def initialize(a,b)&lt;br /&gt;
    @number1 = a&lt;br /&gt;
    @number2 = b&lt;br /&gt;
  end&lt;br /&gt;
  def num1&lt;br /&gt;
  @number1&lt;br /&gt;
  end&lt;br /&gt;
  def num2&lt;br /&gt;
  @number2&lt;br /&gt;
  end  &lt;br /&gt;
  def add(a)&lt;br /&gt;
   puts a.num1+a.num2&lt;br /&gt;
  end    &lt;br /&gt;
  def diff(a)&lt;br /&gt;
    puts a.num1-a.num2&lt;br /&gt;
end&lt;br /&gt;
public:add&lt;br /&gt;
public:diff&lt;br /&gt;
protected:num1&lt;br /&gt;
#private:num2  &lt;br /&gt;
end&lt;br /&gt;
Num1=Number.new(50,60)&lt;br /&gt;
Num1.add(Num1)&lt;br /&gt;
Num1.diff(Num1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;This program runs successfully and prints the output as long as the private method is not accessed. Here, the private method is num2 and should not be invoked in the current context of the object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;in `add': private method `num2' called for #&amp;lt;Number:0x436e18 @number1=50, @number2=60&amp;gt; (NoMethodError)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, the private method num2 can be accessed using the send method. The syntax for accessing the method is '''a.send(:num2)&lt;br /&gt;
&lt;br /&gt;
=='''C#==&lt;br /&gt;
It has 5 specific levels of access control at the class member level.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''1. Public''' : Public access is the least restrictive access level and class members can be accessed anywhere. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''2. Private''' : Private is the most restrictive access level where members are accessed only in the body of the class in which they are declared. This support is also extended to nested classes. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''3. Protected''' : The protected keyword is a member access modifier i.e, it cannot be applied at a class level. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class Number &lt;br /&gt;
{&lt;br /&gt;
	public int x =5;&lt;br /&gt;
        public int y =10; &lt;br /&gt;
	public int add() {&lt;br /&gt;
      		return x+y;&lt;br /&gt;
   	}&lt;br /&gt;
	protected int diff(){&lt;br /&gt;
		return y-x;&lt;br /&gt;
	}&lt;br /&gt;
	private int prod(){&lt;br /&gt;
		return x*y;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Number1&lt;br /&gt;
{&lt;br /&gt;
	public static void Main()&lt;br /&gt;
	{&lt;br /&gt;
		Number num = new Number();&lt;br /&gt;
		num.add();	//access to add&lt;br /&gt;
		num.diff();	// can't as diff is declared protected&lt;br /&gt;
		num.prod();	// can't access as prod is private&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Number2 : Number&lt;br /&gt;
{&lt;br /&gt;
	public static void Main()&lt;br /&gt;
	{&lt;br /&gt;
		Number2 num2 = new Number2();&lt;br /&gt;
		num2.diff(); 	// access to protected member&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''4. Internal''' : It is an access modifier for types and type members. Internal members are accessible only within files in the same assembly.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''5. Protected Internal''': This access control restricts access of members to the class, subclass within the assembly. The difference between protected internal and internal is that, a subclass of the class derived in another assembly can also access the protected internal method.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File1.cs:&lt;br /&gt;
class Number3 &lt;br /&gt;
{&lt;br /&gt;
   internal int x =0;&lt;br /&gt;
   protected internal int y = 0;	&lt;br /&gt;
}&lt;br /&gt;
File2.cs&lt;br /&gt;
class Number4 : Number3&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
      Number4 num4 = new Number4();   &lt;br /&gt;
      num4.x = 4 // error, as x is declared as internal&lt;br /&gt;
      num4.y = 5 // Allowed. As y is protected internal.&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Python==&lt;br /&gt;
&amp;lt;p&amp;gt;Python implements access control in a different way from most other languages in that they don’t have specific access control modifiers. By default all members are public and we precede the member name with ‘__’ (a double underscore) to indicate if the member is private. This feature of python is called as [http://en.wikipedia.org/wiki/Name_mangling Name Mangling]. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;There is no feature in python to implement the protected access control. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number:&lt;br /&gt;
  def __init(self,a,b): // this is a private method&lt;br /&gt;
    self.a = a&lt;br /&gt;
    self.b = b&lt;br /&gt;
  &lt;br /&gt;
  def add():&lt;br /&gt;
   print self.a + self.b&lt;br /&gt;
      	&lt;br /&gt;
  def diff():&lt;br /&gt;
   print self.b - self.a&lt;br /&gt;
&lt;br /&gt;
Num1=Number(50,60)&lt;br /&gt;
Num1.add()&lt;br /&gt;
Num1.diff()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Note that in python the __init method is made to be private as default while programming. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''More on Name Mangling in Python&lt;br /&gt;
&amp;lt;p&amp;gt;Name mangling is a feature of python using which we indicate whether a member is private by just adding underscores, instead of using key words. When we program or debug, it is easier to note that the member is private and thus refrain from accessing it.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Eiffel==&lt;br /&gt;
Eiffel has a different approach to access control compared to the previous object oriented languages like C++ and Java. It uses ''selective export'', which means that different methods and attributes can have different access levels. Also, we can individually specify the access level for each method or attribute. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
feature{NONE} -- indicates nothing can access this code from outside of the class (private)&lt;br /&gt;
	a: INTEGER&lt;br /&gt;
	b: INTEGER&lt;br /&gt;
initialize is &lt;br /&gt;
	do&lt;br /&gt;
		a := 10 &lt;br /&gt;
		b := 20&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
feature{ANY} -- indicates this method can be accessed from anywhere outside of the class(public)&lt;br /&gt;
add: INTEGER is&lt;br /&gt;
	do&lt;br /&gt;
		Result := a+b&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
feature{Number} -- indicates that this method can be accessed only by members of the class Number&lt;br /&gt;
diff: INTEGER is&lt;br /&gt;
	do&lt;br /&gt;
		Result := b-a&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''More on feature:&lt;br /&gt;
&amp;lt;p&amp;gt;Using feature, we can provide varying levels of access to a code in the class. And also we can provide the names of classes that are only allowed to access that part of the code. In the above example, the different access levels that features provide are explained in the comments.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison among different O-O languages=&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&lt;br /&gt;
!Java&lt;br /&gt;
!C++&lt;br /&gt;
!C#&lt;br /&gt;
!Ruby&lt;br /&gt;
!Python&lt;br /&gt;
!Eiffel&lt;br /&gt;
|-&lt;br /&gt;
|Public&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|-&lt;br /&gt;
|Protected&lt;br /&gt;
|Access within the class and sub-classes&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|No protected access&lt;br /&gt;
|Access can be given to only a few of the classes.&lt;br /&gt;
|-&lt;br /&gt;
|Private&lt;br /&gt;
|Cannot be directly accessed from outside the class. Can be accessed by nested classes.&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|-&lt;br /&gt;
|Special feature&lt;br /&gt;
|Default access is package. Any class in a package can access if no modifier is given&lt;br /&gt;
|friend functions(access of private to a specific friend class or method)&lt;br /&gt;
|internal and protected internal&lt;br /&gt;
|send method is used to access private members&lt;br /&gt;
|Name Mangling(use of underscores to indicate access level)&lt;br /&gt;
|Selective export using &amp;quot;feature&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=A short note on the usage of Access Control=&lt;br /&gt;
&lt;br /&gt;
With many access control mechanisms defined, there is always the question of which access control can be used. This is decided at the discretion of the programmer but as a good programming practice, the following can be used.&lt;br /&gt;
&lt;br /&gt;
1.	Use public access only if an interface for a class so that the data can be sent or modified based on external requirements.&lt;br /&gt;
&amp;lt;p&amp;gt;2.	Use of private is advisable whenever we program the internal structure of the program, like the constructors. Some languages, like Ruby make their variables private by default so that modifications from external entities are avoided.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
&lt;br /&gt;
Access control provides powerful mechanism to implement encapsulation and it can find its use in several of the applications. However, if not used with caution, access control can lead to unexpected behavior in the program. It is always important to use the right access control for the situation to avoid ambiguity and ease the maintainability of code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html Access Control in Java] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/kktasw36(v=VS.80).aspx Member Access Control in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.exforsys.com/tutorials/c-plus-plus/c-plus-plus-friend-functions.html C++ friend functions]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Friend_function Implementing friend functions]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/ms173121.aspx Access Modifiers in C#] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Programming Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://rubylearning.com/satishtalim/ruby_access_control.html Access Control in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Name_mangling Name Mangling in OO Langugages]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://docs.python.org/release/1.5/tut/node67.html Name Mangling in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.tutorialspoint.com/python/python_classes_objects.htm Class Objects in Python] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.maths.tcd.ie/~odunlain/eiffel/eiffel_course/eforb.htm Eiffel for Beginners]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Eiffel_(programming_language) More on Eiffel]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.maceiffel.com/Into%20Eiffel.pdf Into Eiffel By Ian Joyner]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Static-typing_%28programming_languages%29#Static_and_dynamic_typing Static and Dynamic Typing]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_2b_rv&amp;diff=51620</id>
		<title>CSC/ECE 517 Fall 2011/ch1 2b rv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_2b_rv&amp;diff=51620"/>
		<updated>2011-10-01T00:05:14Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* C# */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Access Control in O-O Languages&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Access control=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In [http://en.wikipedia.org/wiki/Object-oriented_programming object oriented programming], access control refers to the control of visibility of data and methods. The main idea behind access control is to restrict access to certain parts of the code to external entities. Access control implements [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) encapsulation] by providing varying levels of access to code. The use of access control becomes necessary in any practical environment where selective access is a key criterion. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;For example, only the instructor can be allowed to modify grades of students but all students should be given access to retrieve and view their respective grades.&amp;lt;/p&amp;gt;  &lt;br /&gt;
&amp;lt;p&amp;gt;Access control in different object oriented languages and the underlying details will be covered in this topic.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview of Access Control Mechanisms=&lt;br /&gt;
&lt;br /&gt;
Each O-O language has a specific implementation of access control mechanisms. However, a plethora of the most widely used o-o languages share similar features while implementing access control. Access control mechanisms are applicable to class members like variables and functions. Some level of access control can be applied at the class level. The 3 basic types of access control implementation which is common to some [http://en.wikipedia.org/wiki/Static-typing_%28programming_languages%29#Static_and_dynamic_typing static and dynamic O-O languages] [like C++, C#, Java and Ruby] are &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Public''' : Methods or attributes that are declared to be public can be accessed from any class. This is the least restrictive access control method. For example, we may want everyone in a company to know the names of people working along with them. Thus public access is given to employee's name.&lt;br /&gt;
&lt;br /&gt;
'''Private''' : This mechanism makes the data or method to be visible only in the class in which it is declared. The support is not extended to sub classes. This is the most restrictive access control method. &lt;br /&gt;
In any application, methods which implement the core functionality or require administrator access are declared to be private thereby enforcing limited access. For example, only a manager can be given the authority to review an employee’s performance and award bonus and promotions. &lt;br /&gt;
&lt;br /&gt;
'''Protected''' : The use of protected access allows access of data and methods to be modified by members belonging to the same family. This means that this support is extended to subclasses. Protected access control can be used to support the single interface, multiple implementation concept i.e, [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inheritance]. &lt;br /&gt;
For example, a super class may have a protected method called ComputeArea(). We can have many subclasses like Triangle, Rectangle etc inherit the super class and override the method ComputeArea() to provide their own specific implementation. In a more practical scenario, a person might be allowed to view the medical history of immediate family members. However, people outside the family will not be allowed access to view this medical history. &lt;br /&gt;
&lt;br /&gt;
=Implementing Access Control=&lt;br /&gt;
&lt;br /&gt;
Programming languages implement access control in different ways. We present a few of the languages that use access control and show their implementation.&lt;br /&gt;
&lt;br /&gt;
=='''Java'''==&lt;br /&gt;
In Java, access control is achieved using the modifiers public, private and protected. If a class is not declared with any modifier, then the default access becomes package-private i.e, any object within the package should be able to access this class. &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;'''Public Keyword''' – Other classes can modify public fields unless its declared as [http://en.wikipedia.org/wiki/Final_%28Java%29 final]. The syntax for declaring a variable/method public is as follows &amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;public int x;&lt;br /&gt;
public void print_Hello()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example shown below, the variable studentName is public and hence can be accessed in another class Student2. Similarly, public methods like getName() etc become accessible by other classes. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''Private Keyword''' – This keyword makes the class members private. Private members can only be accessed from within the class. They are not visible even in subclasses. However, visibility and access of private members is extended to nested classes. The syntax for declaring a variable/method private is as follows&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;private String EmpID; &lt;br /&gt;
private void getEmpDetails() &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In the example code below, the method setID is declared to be private. Hence, it cannot be accessed in the subclass of the class Student.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Protected Keyword''' – This keyword when used before a class member makes that member visible to the elements residing in that class and its subclasses. The syntax for declaring a variable/method protected is as follows&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;protected int sides; &lt;br /&gt;
protected void setArea(int sides)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In the example code below, the method setName is declared as protected. Hence, it can be accessed in the subclass NewStudent.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Default access level/Package''' – When no specific access control keyword is given, then the method or variable becomes accessible to all classes under a particular package. In the following example, the integer “packageVar” becomes accessible to all classes included in the package ‘TestPackage1’. Hence, it can be modified in the class Student2.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
package TestPackage1  &lt;br /&gt;
public class Student {  &lt;br /&gt;
&lt;br /&gt;
	public String studentName;&lt;br /&gt;
	public int studentID;&lt;br /&gt;
	int packageVar;&lt;br /&gt;
&lt;br /&gt;
	public String getName() {&lt;br /&gt;
		return studentName;&lt;br /&gt;
	}&lt;br /&gt;
	public int getID() {&lt;br /&gt;
		return studentID;&lt;br /&gt;
	}&lt;br /&gt;
	protected void setName(String s) {&lt;br /&gt;
		studentName = s;&lt;br /&gt;
	}&lt;br /&gt;
	private void setID(int y) {&lt;br /&gt;
		studentID = y;&lt;br /&gt;
	}&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		Student Stu1 = new Student();&lt;br /&gt;
		Stu1.setName(&amp;quot;ABCD&amp;quot;);&lt;br /&gt;
		Stu1.setID(1230013);&lt;br /&gt;
		System.out.println(Stu1.getName() + Stu1.getID());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
public class NewStudent extends Student {	&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		NewStudent NewStu1 = new NewStudent();&lt;br /&gt;
		NewStu1.setName(&amp;quot;EFGH&amp;quot;); 		//Can be accessed &lt;br /&gt;
		NewStu1.setID(350);		// Cannot be accessed as setID is private&lt;br /&gt;
		System.out.println(NewStu1.getName());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
public class Student2 {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
                Student Stu2 = new Student();&lt;br /&gt;
                Stu2.studentName = &amp;quot;Mickey&amp;quot;;     //Public variable of another class can be accessed&lt;br /&gt;
                Stu2.packageVar = 5;             //Default access level&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''C++==&lt;br /&gt;
In C++, we have the three modifiers presented in the overview along with a special type of access control called [http://en.wikipedia.org/wiki/Friend_function friend]. The behavior of public, private and protected modifiers is similar to its Java counterparts. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Friend - A function or class can access the private and protected members of a class if it is declared as a friend of that class. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
{	int a,b;&lt;br /&gt;
	friend int canAccess(Number numb); // Declaring canAccess() to be a friend&lt;br /&gt;
public:&lt;br /&gt;
	int add(int,int);&lt;br /&gt;
protected:&lt;br /&gt;
	int diff(int,int);&lt;br /&gt;
private:&lt;br /&gt;
	int prod(int,int);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	int add(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		return a+b;&lt;br /&gt;
	}&lt;br /&gt;
	int diff(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		if (a&amp;gt;b)&lt;br /&gt;
		 return a-b;&lt;br /&gt;
		else&lt;br /&gt;
		 return b-a;&lt;br /&gt;
	}&lt;br /&gt;
	int prod(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		return a*b;&lt;br /&gt;
	}	&lt;br /&gt;
};&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
  	Number num;&lt;br /&gt;
	int a=10, b=20;	&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Sum =&amp;quot; &amp;lt;&amp;lt; num.add(a,b);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Difference =&amp;quot; &amp;lt;&amp;lt; num.diff(a,b);&lt;br /&gt;
	//cout &amp;lt;&amp;lt; &amp;quot;Product = &amp;quot; &amp;lt;&amp;lt; num.prod(a,b); // this will throw an error if the comments are removed&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Friend function&lt;br /&gt;
int canAccess(Number numb)&lt;br /&gt;
{&lt;br /&gt;
 cout&amp;lt;&amp;lt; &amp;quot;Product for a friend = &amp;quot; &amp;lt;&amp;lt; numb.prod(10,20)  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More about friend functions'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;If a class is declared as a friend in another class, the friend class can access all the private members of the class. This can also be limited in such a way that only few private members of the class can be accessed. By using friend functions or classes, we can provide a flexibility of letting a friend class access restricted members of a class and still keeping the restricted members closed for access by any other class. This will be useful in a few cases.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Ruby==&lt;br /&gt;
Ruby provides the three levels of access controls, private, public and protected with the default being public access. The behavior of public and protected access control is similar to other languages like C++ and Java. &lt;br /&gt;
&amp;lt;p&amp;gt;However, private methods can be called only within the context of the current object. Other object’s private method cannot be invoked. Private methods can be overridden by the sub-classes.In most cases, private methods are used to provide internal functionality to the class. So we need to use a cautious approach in using private methods. If they are overridden by the subclass, we tend to get unexpected behavior in the program.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Note''': Private methods cannot be called outside of the class. Private methods can be called only using the “send” method. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
  def initialize(a,b)&lt;br /&gt;
    @number1 = a&lt;br /&gt;
    @number2 = b&lt;br /&gt;
  end&lt;br /&gt;
  def num1&lt;br /&gt;
  @number1&lt;br /&gt;
  end&lt;br /&gt;
  def num2&lt;br /&gt;
  @number2&lt;br /&gt;
  end  &lt;br /&gt;
  def add(a)&lt;br /&gt;
   puts a.num1+a.num2&lt;br /&gt;
  end    &lt;br /&gt;
  def diff(a)&lt;br /&gt;
    puts a.num1-a.num2&lt;br /&gt;
end&lt;br /&gt;
public:add&lt;br /&gt;
public:diff&lt;br /&gt;
protected:num1&lt;br /&gt;
#private:num2  &lt;br /&gt;
end&lt;br /&gt;
Num1=Number.new(50,60)&lt;br /&gt;
Num1.add(Num1)&lt;br /&gt;
Num1.diff(Num1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;This program runs successfully and prints the output as long as the private method is not accessed. Here, the private method is num2 and should not be invoked in the current context of the object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;in `add': private method `num2' called for #&amp;lt;Number:0x436e18 @number1=50, @number2=60&amp;gt; (NoMethodError)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, the private method num2 can be accessed using the send method. The syntax for accessing the method is '''a.send(:num2)&lt;br /&gt;
&lt;br /&gt;
=='''C#==&lt;br /&gt;
It has 5 specific levels of access control at the class member level.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''1. Public''' : Public access is the least restrictive access level and class members can be accessed anywhere. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''2. Private''' : Private is the most restrictive access level where members are accessed only in the body of the class in which they are declared. This support is also extended to nested classes. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''3. Protected''' : The protected keyword is a member access modifier i.e, it cannot be applied at a class level. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class Number &lt;br /&gt;
{&lt;br /&gt;
	public int x =5;&lt;br /&gt;
        public int y =10; &lt;br /&gt;
	public int add() {&lt;br /&gt;
      		return x+y;&lt;br /&gt;
   	}&lt;br /&gt;
	protected int diff(){&lt;br /&gt;
		return y-x;&lt;br /&gt;
	}&lt;br /&gt;
	private int prod(){&lt;br /&gt;
		return x*y;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Number1&lt;br /&gt;
{&lt;br /&gt;
	public static void Main()&lt;br /&gt;
	{&lt;br /&gt;
		Number num = new Number();&lt;br /&gt;
		num.add();	//access to add&lt;br /&gt;
		num.diff();	// can't as diff is declared protected&lt;br /&gt;
		num.prod();	// can't access as prod is private&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Number2 : Number&lt;br /&gt;
{&lt;br /&gt;
	public static void Main()&lt;br /&gt;
	{&lt;br /&gt;
		Number2 num2 = new Number2();&lt;br /&gt;
		num2.diff(); 	// access to protected member&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''4. Internal''' : It is an access modifier for types and type members. Internal members are accessible only within files in the same assembly.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''5. Protected Internal''': This access control restricts access of members to the class, subclass within the assembly. The difference between protected internal and internal is that, a subclass of the class derived in another assembly can also access the protected internal method.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File1.cs:&lt;br /&gt;
class Number3 &lt;br /&gt;
{&lt;br /&gt;
   internal int x =0;&lt;br /&gt;
   protected internal int y = 0;	&lt;br /&gt;
}&lt;br /&gt;
File2.cs&lt;br /&gt;
class Number4 : Number3&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
      Number4 num4 = new Number4();   &lt;br /&gt;
      num4.x = 4 // error, as x is declared as internal&lt;br /&gt;
      num4.y = 5 // Allowed. As y is protected internal.&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Python==&lt;br /&gt;
&amp;lt;p&amp;gt;Python implements access control in a different way from most other languages in that they don’t have specific access control modifiers. By default all members are public and we precede the member name with ‘__’ (a double underscore) to indicate if the member is private. This feature of python is called as [http://en.wikipedia.org/wiki/Name_mangling Name Mangling]. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;There is no feature in python to implement the protected access control. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number:&lt;br /&gt;
  def __init(self,a,b): // this is a private method&lt;br /&gt;
    self.a = a&lt;br /&gt;
    self.b = b&lt;br /&gt;
  &lt;br /&gt;
  def add():&lt;br /&gt;
   print self.a + self.b&lt;br /&gt;
      	&lt;br /&gt;
  def diff():&lt;br /&gt;
   print self.b - self.a&lt;br /&gt;
&lt;br /&gt;
Num1=Number(50,60)&lt;br /&gt;
Num1.add()&lt;br /&gt;
Num1.diff()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Note that in python the __init method is made to be private as default while programming. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''More on Name Mangling in Python&lt;br /&gt;
&amp;lt;p&amp;gt;Name mangling is a feature of python using which we indicate whether a member is private by just adding underscores, instead of using key words. When we program or debug, it is easier to note that the member is private and thus refrain from accessing it.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Eiffel==&lt;br /&gt;
Eiffel has a different approach to access control compared to the previous object oriented languages like C++ and Java. It uses ''selective export'', which means that different methods and attributes can have different access levels. Also, we can individually specify the access level for each method or attribute. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
feature{NONE} -- indicates nothing can access this code from outside of the class (private)&lt;br /&gt;
	a: INTEGER&lt;br /&gt;
	b: INTEGER&lt;br /&gt;
initialize is &lt;br /&gt;
	do&lt;br /&gt;
		a := 10 &lt;br /&gt;
		b := 20&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
feature{ANY} -- indicates this method can be accessed from anywhere outside of the class(public)&lt;br /&gt;
add: INTEGER is&lt;br /&gt;
	do&lt;br /&gt;
		Result := a+b&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
feature{Number} -- indicates that this method can be accessed only by members of the class Number&lt;br /&gt;
diff: INTEGER is&lt;br /&gt;
	do&lt;br /&gt;
		Result := b-a&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''More on feature:&lt;br /&gt;
&amp;lt;p&amp;gt;Using feature, we can provide varying levels of access to a code in the class. And also we can provide the names of classes that are only allowed to access that part of the code. In the above example, the different access levels that features provide are explained in the comments.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison among different O-O languages=&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&lt;br /&gt;
!Java&lt;br /&gt;
!C++&lt;br /&gt;
!C#&lt;br /&gt;
!Ruby&lt;br /&gt;
!Python&lt;br /&gt;
!Eiffel&lt;br /&gt;
|-&lt;br /&gt;
|Public&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|-&lt;br /&gt;
|Protected&lt;br /&gt;
|Access within the class and sub-classes&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|No protected access&lt;br /&gt;
|Access can be given to only a few of the classes.&lt;br /&gt;
|-&lt;br /&gt;
|Private&lt;br /&gt;
|Cannot be directly accessed from outside the class. Can be accessed by nested classes.&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|-&lt;br /&gt;
|Special feature&lt;br /&gt;
|Default access is package. Any class in a package can access if no modifier is given&lt;br /&gt;
|friend functions(access of private to a specific friend class or method)&lt;br /&gt;
|internal and protected internal&lt;br /&gt;
|send method is used to access private members&lt;br /&gt;
|Name Mangling(use of underscores to indicate access level)&lt;br /&gt;
|Selective export using &amp;quot;feature&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=A short note on the usage of Access Control=&lt;br /&gt;
&lt;br /&gt;
With many access control mechanisms defined, there is always the question of which access control can be used. This is decided at the discretion of the programmer but as a good programming practice, the following can be used.&lt;br /&gt;
&lt;br /&gt;
1.	Use public access only if an interface for a class so that the data can be sent or modified based on external requirements.&lt;br /&gt;
&amp;lt;p&amp;gt;2.	Use of private is advisable whenever we program the internal structure of the program, like the constructors. Some languages, like Ruby make their variables private by default so that modifications from external entities are avoided.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
&lt;br /&gt;
Access control provides powerful mechanism to implement encapsulation and it can find its use in several of the applications. However, if not used with caution, access control can lead to unexpected behavior in the program. It is always important to use the right access control for the situation to avoid ambiguity and ease the maintainability of code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html Access Control in Java] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/kktasw36(v=VS.80).aspx Member Access Control in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.exforsys.com/tutorials/c-plus-plus/c-plus-plus-friend-functions.html C++ friend functions]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Friend_function Implementing friend functions]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/ms173121.aspx Access Modifiers in C#] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Programming Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://rubylearning.com/satishtalim/ruby_access_control.html Access Control in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Name_mangling Name Mangling in OO Langugages]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://docs.python.org/release/1.5/tut/node67.html Name Mangling in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.tutorialspoint.com/python/python_classes_objects.htm Class Objects in Python] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.maths.tcd.ie/~odunlain/eiffel/eiffel_course/eforb.htm Eiffel for Beginners]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Eiffel_(programming_language) More on Eiffel]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.maceiffel.com/Into%20Eiffel.pdf Into Eiffel By Ian Joyner]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Static-typing_%28programming_languages%29#Static_and_dynamic_typing Static and Dynamic Typing]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_2b_rv&amp;diff=51611</id>
		<title>CSC/ECE 517 Fall 2011/ch1 2b rv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_2b_rv&amp;diff=51611"/>
		<updated>2011-09-30T23:26:19Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Access Control in O-O Languages&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
=Introduction to Access control=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In [http://en.wikipedia.org/wiki/Object-oriented_programming object oriented programming], access control refers to the control of visibility of data and methods. The main idea behind access control is to restrict access to certain parts of the code to external entities. Access control implements [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) encapsulation] by providing varying levels of access to code. The use of access control becomes necessary in any practical environment where selective access is a key criterion. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;For example, only the instructor can be allowed to modify grades of students but all students should be given access to retrieve and view their respective grades.&amp;lt;/p&amp;gt;  &lt;br /&gt;
&amp;lt;p&amp;gt;Access control in different object oriented languages and the underlying details will be covered in this topic.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview of Access Control Mechanisms=&lt;br /&gt;
&lt;br /&gt;
Each O-O language has a specific implementation of access control mechanisms. However, a plethora of the most widely used o-o languages share similar features while implementing access control. Access control mechanisms are applicable to class members like variables and functions. Some level of access control can be applied at the class level. The 3 basic types of access control implementation which is common to some [http://en.wikipedia.org/wiki/Static-typing_%28programming_languages%29#Static_and_dynamic_typing static and dynamic O-O languages] [like C++, C#, Java and Ruby] are &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Public''' : Methods or attributes that are declared to be public can be accessed from any class. This is the least restrictive access control method. For example, we may want everyone in a company to know the names of people working along with them. Thus give public access to the Employee's Name to everyone.&lt;br /&gt;
&lt;br /&gt;
'''Private''' : This mechanism makes the data or method to be visible only in the class in which it is declared. The support is not extended to sub classes. This is the most restrictive access control method. &lt;br /&gt;
In any application, methods which implement the core functionality or require administrator access are declared to be private thereby enforcing limited access. For example, only a manager can be given the authority to review an employee’s performance and award bonus and promotions. &lt;br /&gt;
&lt;br /&gt;
'''Protected''' : The use of protected access allows access of data and methods to be modified by members belonging to the same family. This means that this support is extended to subclasses. Protected access control can be used to support the single interface, multiple implementation concept i.e, [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inheritance]. &lt;br /&gt;
For example, a super class may have a protected method called ComputeArea(). We can have many subclasses like Triangle, Rectangle etc inherit the super class and override the method ComputeArea() to provide their own specific implementation.&lt;br /&gt;
&lt;br /&gt;
=Implementing Access Control=&lt;br /&gt;
&lt;br /&gt;
Access control is implemented in different languages in their own way.We present a few of the languages that use access control and show their implementation.&lt;br /&gt;
&lt;br /&gt;
=='''Java'''==&lt;br /&gt;
In Java, access control is achieved using the modifiers public, private and protected. If a class is not declared with any modifier, then the default access becomes package-private i.e, any object within the package should be able to access this class. &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;'''Public Keyword''' – Other classes can modify public fields unless its declared as final. The syntax for declaring a variable/method public is as follows &amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;public int x;&lt;br /&gt;
public void print_Hello()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example shown below, the variable studentName is public and hence can be accessed in another class Student2. Similarly, public methods like getName() etc become accessible by other classes. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''Private Keyword''' – This keyword makes the class members private. Private members can only be accessed from within the class. They are not visible even in subclasses. However, visibility and access of private members is extended to nested classes. The syntax for declaring a variable/method private is as follows&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;private String EmpID; &lt;br /&gt;
private void getEmpDetails() &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In the example code below, the method setID is declared to be private. Hence, it cannot be accessed in the subclass of the class Student.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Protected Keyword''' – This keyword when used before a class member makes that member visible to the elements residing in that class and its subclasses. The syntax for declaring a variable/method protected is as follows&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;protected int sides; &lt;br /&gt;
protected void setArea(int sides)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In the example code below, the method setName is declared as protected. Hence, it can be accessed in the subclass NewStudent.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Default access level/Package''' – When no specific access control keyword is given, then the method or variable becomes accessible to all classes under a particular package. In the following example, the integer “packageVar” becomes accessible to all classes included in the package ‘TestPackage1’. Hence, it can be modified in the class Student2.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
package TestPackage1  &lt;br /&gt;
public class Student {  &lt;br /&gt;
&lt;br /&gt;
	public String studentName;&lt;br /&gt;
	public int studentID;&lt;br /&gt;
	int packageVar;&lt;br /&gt;
&lt;br /&gt;
	public String getName() {&lt;br /&gt;
		return studentName;&lt;br /&gt;
	}&lt;br /&gt;
	public int getID() {&lt;br /&gt;
		return studentID;&lt;br /&gt;
	}&lt;br /&gt;
	protected void setName(String s) {&lt;br /&gt;
		studentName = s;&lt;br /&gt;
	}&lt;br /&gt;
	private void setID(int y) {&lt;br /&gt;
		studentID = y;&lt;br /&gt;
	}&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		Student Stu1 = new Student();&lt;br /&gt;
		Stu1.setName(&amp;quot;ABCD&amp;quot;);&lt;br /&gt;
		Stu1.setID(1230013);&lt;br /&gt;
		System.out.println(Stu1.getName() + Stu1.getID());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
public class NewStudent extends Student {	&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		NewStudent NewStu1 = new NewStudent();&lt;br /&gt;
		NewStu1.setName(&amp;quot;EFGH&amp;quot;); 		//Can be accessed &lt;br /&gt;
		NewStu1.setID(350);		// Cannot be accessed as setID is private&lt;br /&gt;
		System.out.println(NewStu1.getName());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
public class Student2 {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
                Student Stu2 = new Student();&lt;br /&gt;
                Stu2.studentName = &amp;quot;Mickey&amp;quot;;     //Public variable of another class can be accessed&lt;br /&gt;
                Stu2.packageVar = 5;             //Default access level&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''C++==&lt;br /&gt;
In C++, we have the three modifiers presented in the overview along with a special type of access control called [http://en.wikipedia.org/wiki/Friend_function friend]. The behavior of public, private and protected modifiers is similar to its Java counterparts. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Friend - A function or class can access the private and protected members of a class if it is declared as a friend of that class. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
{	int a,b;&lt;br /&gt;
	friend int canAccess(Number numb); // Declaring canAccess() to be a friend&lt;br /&gt;
public:&lt;br /&gt;
	int add(int,int);&lt;br /&gt;
protected:&lt;br /&gt;
	int diff(int,int);&lt;br /&gt;
private:&lt;br /&gt;
	int prod(int,int);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	int add(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		return a+b;&lt;br /&gt;
	}&lt;br /&gt;
	int diff(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		if (a&amp;gt;b)&lt;br /&gt;
		 return a-b;&lt;br /&gt;
		else&lt;br /&gt;
		 return b-a;&lt;br /&gt;
	}&lt;br /&gt;
	int prod(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		return a*b;&lt;br /&gt;
	}	&lt;br /&gt;
};&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
  	Number num;&lt;br /&gt;
	int a=10, b=20;	&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Sum =&amp;quot; &amp;lt;&amp;lt; num.add(a,b);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Difference =&amp;quot; &amp;lt;&amp;lt; num.diff(a,b);&lt;br /&gt;
	//cout &amp;lt;&amp;lt; &amp;quot;Product = &amp;quot; &amp;lt;&amp;lt; num.prod(a,b); // this will throw an error if the comments are removed&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Friend function&lt;br /&gt;
int canAccess(Number numb)&lt;br /&gt;
{&lt;br /&gt;
 cout&amp;lt;&amp;lt; &amp;quot;Product for a friend = &amp;quot; &amp;lt;&amp;lt; numb.prod(10,20)  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More about friend functions'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;If a class is declared as a friend in another class, the friend class can access all the private members of the class. This can also be limited in such a way that only few private members of the class can be accessed. By using friend functions or classes, we can provide a flexibility of letting a friend class access restricted members of a class and still keeping the restricted members closed for access by any other class. This will be useful in a few cases.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Ruby==&lt;br /&gt;
Ruby provides the three levels of access controls, private, public and protected with the default being public access. The behavior of public and protected access control is similar to other languages like C++ and Java. &lt;br /&gt;
&amp;lt;p&amp;gt;However, private methods can be called only within the context of the current object. Other object’s private method cannot be invoked. Private methods can be overridden by the sub-classes.In most cases, private methods are used to provide internal functionality to the class. So we need to use a cautious approach in using private methods. If they are overridden by the subclass, we tend to get unexpected behavior in the program.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Note''': Private methods cannot be called outside of the class. Private methods can be called only using the “send” method. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
  def initialize(a,b)&lt;br /&gt;
    @number1 = a&lt;br /&gt;
    @number2 = b&lt;br /&gt;
  end&lt;br /&gt;
  def num1&lt;br /&gt;
  @number1&lt;br /&gt;
  end&lt;br /&gt;
  def num2&lt;br /&gt;
  @number2&lt;br /&gt;
  end  &lt;br /&gt;
  def add(a)&lt;br /&gt;
   puts a.num1+a.num2&lt;br /&gt;
  end    &lt;br /&gt;
  def diff(a)&lt;br /&gt;
    puts a.num1-a.num2&lt;br /&gt;
end&lt;br /&gt;
public:add&lt;br /&gt;
public:diff&lt;br /&gt;
protected:num1&lt;br /&gt;
#private:num2  &lt;br /&gt;
end&lt;br /&gt;
Num1=Number.new(50,60)&lt;br /&gt;
Num1.add(Num1)&lt;br /&gt;
Num1.diff(Num1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;This program runs successfully and prints the output as long as the private method is not accessed. Here, the private method is num2 and should not be invoked in the current context of the object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;in `add': private method `num2' called for #&amp;lt;Number:0x436e18 @number1=50, @number2=60&amp;gt; (NoMethodError)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, the private method num2 can be accessed using the send method. The syntax for accessing the method is '''a.send(:num2)&lt;br /&gt;
&lt;br /&gt;
=='''C#==&lt;br /&gt;
It has 5 specific levels of access control at the class member level.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''1. Public''' : Public access is the least restrictive access level and class members can be accessed anywhere. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''2. Private''' : Private is the most restrictive access level where members are accessed only in the body of the class in which they are declared. This support is also extended to nested classes. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''3. Protected''' : The protected keyword is a member access modifier i.e, it cannot be applied at a class level. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A &lt;br /&gt;
{&lt;br /&gt;
	public int x;&lt;br /&gt;
        protected int y = 20; &lt;br /&gt;
	private int c;&lt;br /&gt;
	public double AccessC() {&lt;br /&gt;
      		return c;&lt;br /&gt;
   	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class B&lt;br /&gt;
{&lt;br /&gt;
	public static void Main()&lt;br /&gt;
	{&lt;br /&gt;
		A ax = new A();&lt;br /&gt;
		ax.x = 10;	//access to public members&lt;br /&gt;
		ax.c = 5;	// can't as 'c' is declared private&lt;br /&gt;
		int try = ax.AccessC();	// error thrown as 'c' is private&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class C : A&lt;br /&gt;
{&lt;br /&gt;
	public static void Main()&lt;br /&gt;
	{&lt;br /&gt;
		A a2 = new A();&lt;br /&gt;
		a2.y = 10; 	// access to protected member&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''4. Internal''' : It is an access modifier for types and type members. Internal members are accessible only within files in the same assembly.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''5. Protected Internal''': This access control restricts access of members to the class, subclass within the assembly. The difference between protected internal and internal is that, a subclass of the class derived in another assembly can also access the protected internal method.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File1.cs:&lt;br /&gt;
class Class1 &lt;br /&gt;
{&lt;br /&gt;
   internal static int Random = 0;&lt;br /&gt;
   protected internal int Access = 0;	&lt;br /&gt;
}&lt;br /&gt;
File2.cs&lt;br /&gt;
class Class2 : Class1&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
      Class1 c1 = new Class1();   &lt;br /&gt;
      c1.Random = 4 // error, Class1 not visible outside assembly&lt;br /&gt;
      c1.Access = 5 // Allowed. As Access is protected internal.&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Python==&lt;br /&gt;
&amp;lt;p&amp;gt;Python implements access control in a different way from most other languages in that they don’t have specific access control modifiers. By default all members are public and we precede the member name with ‘__’ (a double underscore) to indicate if the member is private. This feature of python is called as [http://en.wikipedia.org/wiki/Name_mangling Name Mangling]. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;There is no feature in python to implement the protected access control. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number:&lt;br /&gt;
  def __init(self,a,b): // this is a private method&lt;br /&gt;
    self.a = a&lt;br /&gt;
    self.b = b&lt;br /&gt;
  &lt;br /&gt;
  def add():&lt;br /&gt;
   print self.a + self.b&lt;br /&gt;
      	&lt;br /&gt;
  def diff():&lt;br /&gt;
   print self.b - self.a&lt;br /&gt;
&lt;br /&gt;
Num1=Number(50,60)&lt;br /&gt;
Num1.add()&lt;br /&gt;
Num1.diff()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Note that in python the __init method is made to be private as default while programming. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''More on Name Mangling in Python&lt;br /&gt;
&amp;lt;p&amp;gt;Name mangling is a feature of python using which we indicate whether a member is private by just adding underscores, instead of using key words. When we program or debug, it is easier to note that the member is private and thus refrain from accessing it.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Eiffel==&lt;br /&gt;
Eiffel has a different approach to access control compared to the previous object oriented languages like C++ and Java. It uses ''selective export'', which means that different methods and attributes can have different access levels. Also, we can individually specify the access level for each method or attribute. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
feature{NONE} -- indicates nothing can access this code from outside of the class (private)&lt;br /&gt;
	a: INTEGER&lt;br /&gt;
	b: INTEGER&lt;br /&gt;
initialize is &lt;br /&gt;
	do&lt;br /&gt;
		a := 10 &lt;br /&gt;
		b := 20&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
feature{ANY} -- indicates this method can be accessed from anywhere outside of the class(public)&lt;br /&gt;
add: INTEGER is&lt;br /&gt;
	do&lt;br /&gt;
		Result := a+b&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
feature{Number} -- indicates that this method can be accessed only by members of the class Number&lt;br /&gt;
diff: INTEGER is&lt;br /&gt;
	do&lt;br /&gt;
		Result := b-a&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''More on feature:&lt;br /&gt;
&amp;lt;p&amp;gt;Using feature, we can provide varying levels of access to a code in the class. And also we can provide the names of classes that are only allowed to access that part of the code. In the above example, the different access levels that features provide are explained in the comments.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison among different O-O languages=&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&lt;br /&gt;
!Java&lt;br /&gt;
!C++&lt;br /&gt;
!C#&lt;br /&gt;
!Ruby&lt;br /&gt;
!Python&lt;br /&gt;
!Eiffel&lt;br /&gt;
|-&lt;br /&gt;
|Public&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|-&lt;br /&gt;
|Protected&lt;br /&gt;
|Access within the class and sub-classes&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|No protected access&lt;br /&gt;
|Access can be given to only a few of the classes.&lt;br /&gt;
|-&lt;br /&gt;
|Private&lt;br /&gt;
|Cannot be directly accessed from outside the class. Can be accessed by nested classes.&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|-&lt;br /&gt;
|Special feature&lt;br /&gt;
|Default access is package. Any class in a package can access if no modifier is given&lt;br /&gt;
|friend functions(access of private to a specific friend class or method)&lt;br /&gt;
|internal and protected internal&lt;br /&gt;
|send method is used to access private members&lt;br /&gt;
|Name Mangling(use of underscores to indicate access level)&lt;br /&gt;
|Selective export using &amp;quot;feature&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=A short note on the usage of Access Control=&lt;br /&gt;
&lt;br /&gt;
With many access control mechanisms defined, there is always the question of which access control can be used. This is decided at the discretion of the programmer but as a good programming practice, the following can be used.&lt;br /&gt;
&lt;br /&gt;
1.	Use public access only if an interface for a class so that the data can be sent or modified based on external requirements.&lt;br /&gt;
&amp;lt;p&amp;gt;2.	Use of private is advisable whenever we program the internal structure of the program, like the constructors. Some languages, like Ruby make their variables private by default so that modifications from external entities are avoided.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
&lt;br /&gt;
Access control provides powerful mechanism to implement encapsulation and it can find its use in several of the applications. However, if not used with caution, access control can lead to unexpected behavior in the program. It is always important to use the right access control for the situation to avoid ambiguity and ease the maintainability of code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html Access Control in Java] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/kktasw36(v=VS.80).aspx Member Access Control in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.exforsys.com/tutorials/c-plus-plus/c-plus-plus-friend-functions.html C++ friend functions]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Friend_function Implementing friend functions]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/ms173121.aspx Access Modifiers in C#] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Programming Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://rubylearning.com/satishtalim/ruby_access_control.html Access Control in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Name_mangling Name Mangling in OO Langugages]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://docs.python.org/release/1.5/tut/node67.html Name Mangling in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.tutorialspoint.com/python/python_classes_objects.htm Class Objects in Python] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.maths.tcd.ie/~odunlain/eiffel/eiffel_course/eforb.htm Eiffel for Beginners]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Eiffel_(programming_language) More on Eiffel]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.maceiffel.com/Into%20Eiffel.pdf Into Eiffel By Ian Joyner]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Static-typing_%28programming_languages%29#Static_and_dynamic_typing Static and Dynamic Typing]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_2b_rv&amp;diff=50331</id>
		<title>CSC/ECE 517 Fall 2011/ch1 2b rv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2011/ch1_2b_rv&amp;diff=50331"/>
		<updated>2011-09-22T19:22:20Z</updated>

		<summary type="html">&lt;p&gt;Abalasu3: /* Comparison among different O-O languages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__TOC__&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Introduction to Access control=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In [http://en.wikipedia.org/wiki/Object-oriented_programming object oriented programming], access control refers to the control of visibility of data and methods. The main idea behind access control is to hide the underlying implementation of functions behind its public interface. Access control implements [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) encapsulation] by providing varying levels of access to code. The use of access control becomes necessary in any practical environment where selective access is a key criterion. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;For example, only the instructor can be allowed to modify grades of students but all students should be given access to retrieve and view their respective grades.&amp;lt;/p&amp;gt;  &lt;br /&gt;
&amp;lt;p&amp;gt;Access control in different object oriented languages and the underlying details will be covered in this topic.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview of Access Control Mechanisms=&lt;br /&gt;
Each O-O language has a specific implementation of access control mechanisms. However, a plethora of the most widely used o-o languages share similar features while implementing access control. Access control mechanisms are applicable to class members like variables and functions. Some level of access control can be applied at the class level. The 3 basic types of access control implementation which is common to some static and dynamic O-O languages [like C++, C#, Java and Ruby] are &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
'''Public''' : Methods or attributes that are declared to be public can be accessed from any class. This is the least restrictive access control method. &lt;br /&gt;
&lt;br /&gt;
'''Private''' : This mechanism makes the data or method to be visible only in the class in which it is declared. The support is not extended to sub classes. This is the most restrictive access control method. &lt;br /&gt;
In any application, methods which implement the core functionality or require administrator access are declared to be private thereby enforcing limited access. For example, only a manager can be given the authority to review an employee’s performance and award bonus and promotions. &lt;br /&gt;
&lt;br /&gt;
'''Protected''' : The use of protected access allows access of data and methods to be modified by members belonging to the same family. This means that this support is extended to subclasses. Protected access control can be used to support the single interface, multiple implementation concept i.e, [http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming) inheritance]. &lt;br /&gt;
For example, a super class may have a protected method called ComputeArea(). We can have many subclasses like Triangle, Rectangle etc inherit the super class and override the method ComputeArea() to provide their own specific implementation.&lt;br /&gt;
&lt;br /&gt;
=Implementing Access Control=&lt;br /&gt;
&lt;br /&gt;
	Access control is implemented in different languages in their own way.We present a few of the languages that use access control and show their implementation.&lt;br /&gt;
&lt;br /&gt;
=='''Java'''==&lt;br /&gt;
In Java, access control is achieved using the modifiers public, private and protected. If a class is not declared with any modifier, then the default access becomes package-private i.e, any object within the package should be able to access this class. &lt;br /&gt;
 &lt;br /&gt;
&amp;lt;p&amp;gt;'''Public Keyword''' – Other classes can modify public fields unless its declared as final. The syntax for declaring a variable/method public is as follows &amp;lt;br&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;public int x;&lt;br /&gt;
public void print_Hello()&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the example shown below, the variable studentName is public and hence can be accessed in another class Student2. Similarly, public methods like getName() etc become accessible by other classes. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''Private Keyword''' – This keyword makes the class members private. Private members can only be accessed from within the class. They are not visible even in subclasses. However, visibility and access of private members is extended to nested classes. The syntax for declaring a variable/method private is as follows&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;private String EmpID; &lt;br /&gt;
private void getEmpDetails() &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In the example code below, the method setID is declared to be private. Hence, it cannot be accessed in the subclass of the class Student.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Protected Keyword''' – This keyword when used before a class member makes that member visible to the elements residing in that class and its subclasses. The syntax for declaring a variable/method protected is as follows&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;protected int sides; &lt;br /&gt;
protected void setArea(int sides)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;In the example code below, the method setName is declared as protected. Hence, it can be accessed in the subclass NewStudent.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Default access level/Package''' – When no specific access control keyword is given, then the method or variable becomes accessible to all classes under a particular package. In the following example, the integer “packageVar” becomes accessible to all classes included in the package ‘TestPackage1’. Hence, it can be modified in the class Student2.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
package TestPackage1  &lt;br /&gt;
public class Student {  &lt;br /&gt;
&lt;br /&gt;
	public String studentName;&lt;br /&gt;
	public int studentID;&lt;br /&gt;
	int packageVar;&lt;br /&gt;
&lt;br /&gt;
	public String getName() {&lt;br /&gt;
		return studentName;&lt;br /&gt;
	}&lt;br /&gt;
	public int getID() {&lt;br /&gt;
		return studentID;&lt;br /&gt;
	}&lt;br /&gt;
	protected void setName(String s) {&lt;br /&gt;
		studentName = s;&lt;br /&gt;
	}&lt;br /&gt;
	private void setID(int y) {&lt;br /&gt;
		studentID = y;&lt;br /&gt;
	}&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		Student Stu1 = new Student();&lt;br /&gt;
		Stu1.setName(&amp;quot;ABCD&amp;quot;);&lt;br /&gt;
		Stu1.setID(1230013);&lt;br /&gt;
		System.out.println(Stu1.getName() + Stu1.getID());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
public class NewStudent extends Student {	&lt;br /&gt;
	public static void main(String[] args) {&lt;br /&gt;
		NewStudent NewStu1 = new NewStudent();&lt;br /&gt;
		NewStu1.setName(&amp;quot;EFGH&amp;quot;); 		//Can be accessed &lt;br /&gt;
		NewStu1.setID(350);		// Cannot be accessed as setID is private&lt;br /&gt;
		System.out.println(NewStu1.getName());&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
public class Student2 {&lt;br /&gt;
        public static void main(String[] args) {&lt;br /&gt;
                Student Stu2 = new Student();&lt;br /&gt;
                Stu2.studentName = &amp;quot;Mickey&amp;quot;;     //Public variable of another class can be accessed&lt;br /&gt;
                Stu2.packageVar = 5;             //Default access level&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''C++==&lt;br /&gt;
&lt;br /&gt;
In C++, we have the three modifiers presented in the overview along with a special type of access control called [http://en.wikipedia.org/wiki/Friend_function friend]. The behavior of public, private and protected modifiers is similar to its Java counterparts. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Friend - A function or class can access the private and protected members of a class if it is declared as a friend of that class. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
{	int a,b;&lt;br /&gt;
	friend int canAccess(Number numb); // Declaring canAccess() to be a friend&lt;br /&gt;
public:&lt;br /&gt;
	int add(int,int);&lt;br /&gt;
protected:&lt;br /&gt;
	int diff(int,int);&lt;br /&gt;
private:&lt;br /&gt;
	int prod(int,int);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
	int add(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		return a+b;&lt;br /&gt;
	}&lt;br /&gt;
	int diff(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		if (a&amp;gt;b)&lt;br /&gt;
		 return a-b;&lt;br /&gt;
		else&lt;br /&gt;
		 return b-a;&lt;br /&gt;
	}&lt;br /&gt;
	int prod(int a,int b)&lt;br /&gt;
	{&lt;br /&gt;
		return a*b;&lt;br /&gt;
	}	&lt;br /&gt;
};&lt;br /&gt;
public static void main()&lt;br /&gt;
{&lt;br /&gt;
  	Number num;&lt;br /&gt;
	int a=10, b=20;	&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Sum =&amp;quot; &amp;lt;&amp;lt; num.add(a,b);&lt;br /&gt;
	cout &amp;lt;&amp;lt; &amp;quot;Difference =&amp;quot; &amp;lt;&amp;lt; num.diff(a,b);&lt;br /&gt;
	//cout &amp;lt;&amp;lt; &amp;quot;Product = &amp;quot; &amp;lt;&amp;lt; num.prod(a,b); // this will throw an error if the comments are removed&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Friend function&lt;br /&gt;
int canAccess(Number numb)&lt;br /&gt;
{&lt;br /&gt;
 cout&amp;lt;&amp;lt; &amp;quot;Product for a friend = &amp;quot; &amp;lt;&amp;lt; numb.prod(10,20)  &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''More about friend functions'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;If a class is declared as a friend in another class, the friend class can access all the private members of the class. This can also be limited in such a way that only few private members of the class can be accessed. By using friend functions or classes, we can provide a flexibility of letting a friend class access restricted members of a class and still keeping the restricted members closed for access by any other class. This will be useful in a few cases.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Ruby==&lt;br /&gt;
&lt;br /&gt;
Ruby provides the three levels of access controls, private, public and protected with the default being public access. The behavior of public and protected access control is similar to other languages like C++ and Java. &lt;br /&gt;
&amp;lt;p&amp;gt;However, private methods can be called only within the context of the current object. Other object’s private method cannot be invoked. Private methods can be overridden by the sub-classes.In most cases, private methods are used to provide internal functionality to the class. So we need to use a cautious approach in using private methods. If they are overridden by the subclass, we tend to get unexpected behavior in the program.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''Note''': Private methods cannot be called outside of the class. Private methods can be called only using the “send” method. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
  def initialize(a,b)&lt;br /&gt;
    @number1 = a&lt;br /&gt;
    @number2 = b&lt;br /&gt;
  end&lt;br /&gt;
  def num1&lt;br /&gt;
  @number1&lt;br /&gt;
  end&lt;br /&gt;
  def num2&lt;br /&gt;
  @number2&lt;br /&gt;
  end  &lt;br /&gt;
  def add(a)&lt;br /&gt;
   puts a.num1+a.num2&lt;br /&gt;
  end    &lt;br /&gt;
  def diff(a)&lt;br /&gt;
    puts a.num1-a.num2&lt;br /&gt;
end&lt;br /&gt;
public:add&lt;br /&gt;
public:diff&lt;br /&gt;
protected:num1&lt;br /&gt;
#private:num2  &lt;br /&gt;
end&lt;br /&gt;
Num1=Number.new(50,60)&lt;br /&gt;
Num1.add(Num1)&lt;br /&gt;
Num1.diff(Num1)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;This program runs successfully and prints the output as long as the private method is not accessed. Here, the private method is num2 and should not be invoked in the current context of the object.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;in `add': private method `num2' called for #&amp;lt;Number:0x436e18 @number1=50, @number2=60&amp;gt; (NoMethodError)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, the private method num2 can be accessed using the send method. The syntax for accessing the method is '''a.send(:num2)&lt;br /&gt;
=='''C#==&lt;br /&gt;
&lt;br /&gt;
It has 5 specific levels of access control at the class member level.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''1. Public''' : Public access is the least restrictive access level and class members can be accessed anywhere. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''2. Private''' : Private is the most restrictive access level where members are accessed only in the body of the class in which they are declared. This support is also extended to nested classes. &amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''3. Protected''' : The protected keyword is a member access modifier i.e, it cannot be applied at a class level. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class A &lt;br /&gt;
{&lt;br /&gt;
	public int x;&lt;br /&gt;
        protected int y = 20; &lt;br /&gt;
	private int c;&lt;br /&gt;
	public double AccessC() {&lt;br /&gt;
      		return c;&lt;br /&gt;
   	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class B&lt;br /&gt;
{&lt;br /&gt;
	public static void Main()&lt;br /&gt;
	{&lt;br /&gt;
		A ax = new A();&lt;br /&gt;
		ax.x = 10;	//access to public members&lt;br /&gt;
		ax.c = 5;	// can't as 'c' is declared private&lt;br /&gt;
		int try = ax.AccessC();	// error thrown as 'c' is private&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class C : A&lt;br /&gt;
{&lt;br /&gt;
	public static void Main()&lt;br /&gt;
	{&lt;br /&gt;
		A a2 = new A();&lt;br /&gt;
		a2.y = 10; 	// access to protected member&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;'''4. Internal''' : It is an access modifier for types and type members. Internal members are accessible only within files in the same assembly.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;'''5. Protected Internal''': This access control restricts access of members to the class, subclass within the assembly. The difference between protected internal and internal is that, a subclass of the class derived in another assembly can also access the protected internal method.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
File1.cs:&lt;br /&gt;
class Class1 &lt;br /&gt;
{&lt;br /&gt;
   internal static int Random = 0;&lt;br /&gt;
   protected internal int Access = 0;	&lt;br /&gt;
}&lt;br /&gt;
File2.cs&lt;br /&gt;
class Class2 : Class1&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
      Class1 c1 = new Class1();   &lt;br /&gt;
      c1.Random = 4 // error, Class1 not visible outside assembly&lt;br /&gt;
      c1.Access = 5 // Allowed. As Access is protected internal.&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Python==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Python implements access control in a different way from most other languages in that they don’t have specific access control modifiers. By default all members are public and we precede the member name with ‘__’ (a double underscore) to indicate if the member is private. This feature of python is called as [http://en.wikipedia.org/wiki/Name_mangling Name Mangling]. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;There is no feature in python to implement the protected access control. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number:&lt;br /&gt;
  def __init(self,a,b): // this is a private method&lt;br /&gt;
    self.a = a&lt;br /&gt;
    self.b = b&lt;br /&gt;
  &lt;br /&gt;
  def add():&lt;br /&gt;
   print self.a + self.b&lt;br /&gt;
      	&lt;br /&gt;
  def diff():&lt;br /&gt;
   print self.b - self.a&lt;br /&gt;
&lt;br /&gt;
Num1=Number(50,60)&lt;br /&gt;
Num1.add()&lt;br /&gt;
Num1.diff()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Note that in python the __init method is made to be private as default while programming. &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''More on Name Mangling in Python&lt;br /&gt;
&amp;lt;p&amp;gt;Name mangling is a feature of python using which we indicate whether a member is private by just adding underscores, instead of using key words. When we program or debug, it is easier to note that the member is private and thus refrain from accessing it.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=='''Eiffel==&lt;br /&gt;
&lt;br /&gt;
Eiffel has a different approach to access control compared to the previous object oriented languages like C++ and Java. It uses ''selective export'', which means that different methods and attributes can have different access levels. Also, we can individually specify the access level for each method or attribute. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Number&lt;br /&gt;
feature{NONE} -- indicates nothing can access this code from outside of the class (private)&lt;br /&gt;
	a: INTEGER&lt;br /&gt;
	b: INTEGER&lt;br /&gt;
initialize is &lt;br /&gt;
	do&lt;br /&gt;
		a := 10 &lt;br /&gt;
		b := 20&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
feature{ANY} -- indicates this method can be accessed from anywhere outside of the class(public)&lt;br /&gt;
add: INTEGER is&lt;br /&gt;
	do&lt;br /&gt;
		Result := a+b&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
feature{Number} -- indicates that this method can be accessed only by members of the class Number&lt;br /&gt;
diff: INTEGER is&lt;br /&gt;
	do&lt;br /&gt;
		Result := b-a&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''More on feature:&lt;br /&gt;
&amp;lt;p&amp;gt;Using feature, we can provide varying levels of access to a code in the class. And also we can provide the names of classes that are only allowed to access that part of the code. In the above example, the different access levels that features provide are explained in the comments.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Comparison among different O-O languages=&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
!&lt;br /&gt;
!Java&lt;br /&gt;
!C++&lt;br /&gt;
!C#&lt;br /&gt;
!Ruby&lt;br /&gt;
!Python&lt;br /&gt;
!Eiffel&lt;br /&gt;
|-&lt;br /&gt;
|Public&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|Can be accessed outside of class&lt;br /&gt;
|-&lt;br /&gt;
|Protected&lt;br /&gt;
|Access within the class and sub-classes&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|Access within the class and subclasses&lt;br /&gt;
|No protected access&lt;br /&gt;
|Access can be given to only a few of the classes.&lt;br /&gt;
|-&lt;br /&gt;
|Private&lt;br /&gt;
|Cannot be directly accessed from outside the class. Can be accessed by nested classes.&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|Cannot be directly accessed from outside the class&lt;br /&gt;
|-&lt;br /&gt;
|Special feature&lt;br /&gt;
|Default access is package. Any class in a package can access if no modifier is given&lt;br /&gt;
|friend functions(access of private to a specific friend class or method)&lt;br /&gt;
|internal and protected internal&lt;br /&gt;
|send method is used to access private members&lt;br /&gt;
|Name Mangling(use of underscores to indicate access level)&lt;br /&gt;
|Selective export using &amp;quot;feature&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=A short note on the usage of Access Control=&lt;br /&gt;
&lt;br /&gt;
With many access control mechanisms defined, there is always the question of which access control can be used. This is decided at the discretion of the programmer but as a good programming practice, the following can be used.&lt;br /&gt;
&lt;br /&gt;
1.	Use public access only if an interface for a class so that the data can be sent or modified based on external requirements.&lt;br /&gt;
&amp;lt;p&amp;gt;2.	Use of private is advisable whenever we program the internal structure of the program, like the constructors. Some languages, like Ruby make their variables private by default so that modifications from external entities are avoided.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Summary=&lt;br /&gt;
Access control provides powerful mechanism to implement encapsulation and it can find its use in several of the applications. However, if not used with caution, access control can lead to unexpected behavior in the program. It is always important to use the right access control for the situation to avoid ambiguity and ease the maintainability of code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Object-oriented_programming Object Oriented Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Encapsulation_(object-oriented_programming) Encapsulation]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://download.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html Access Control in Java] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/kktasw36(v=VS.80).aspx Member Access Control in C++]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.exforsys.com/tutorials/c-plus-plus/c-plus-plus-friend-functions.html C++ friend functions]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Friend_function Implementing friend functions]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://msdn.microsoft.com/en-us/library/ms173121.aspx Access Modifiers in C#] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_classes.html Programming Ruby] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://rubylearning.com/satishtalim/ruby_access_control.html Access Control in Ruby]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Name_mangling Name Mangling in OO Langugages]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://docs.python.org/release/1.5/tut/node67.html Name Mangling in Python]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.tutorialspoint.com/python/python_classes_objects.htm Class Objects in Python] &amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.maths.tcd.ie/~odunlain/eiffel/eiffel_course/eforb.htm Eiffel for Beginners]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Eiffel_(programming_language) More on Eiffel]&amp;lt;br&amp;gt;&lt;br /&gt;
* [http://www.maceiffel.com/Into%20Eiffel.pdf Into Eiffel By Ian Joyner]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abalasu3</name></author>
	</entry>
</feed>