<?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=Ashray</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=Ashray"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Ashray"/>
	<updated>2026-06-02T15:28:39Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74362</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74362"/>
		<updated>2013-03-23T14:36:32Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once here]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found [http://152.46.17.15:8081/openmrs-standalone/index.htm here] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github [https://github.com/ashrayn/openmrs-module-m604 here]&lt;br /&gt;
&lt;br /&gt;
The module's github readme file can be seen [https://github.com/ashrayn/openmrs-module-m604/blob/master/README.txt here]&lt;br /&gt;
&lt;br /&gt;
Quick Start:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login to OpenMRS with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
To open a list of all data created for demonstration purposes, one would have to access the code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/data/SampleData.java here]. If the user decides to add his/her data of his own, please refer to the section [https://github.com/ashrayn/openmrs-module-m604/blob/master/README.txt User Guide in readme.txt] &lt;br /&gt;
This is not necessary if in case the user already has the relevant data on his/her local machine. &lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
Quite a few design patterns were used to design this module. &lt;br /&gt;
===Model View Controller===&lt;br /&gt;
As there was significant UI  and Database functionality, the use of MVC was inevitable [http://domino.watson.ibm.com/library/cyberdig.nsf/1e4115aea78b6e7c85256b360066f0d4/696cfba5d4b1e68985256a1e00626e27!OpenDocument MVC] &lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl ChangeRelationshipServiceImpl] corresponds to the model. This class contains the functions to fire queries to the database and also insert new records/update existing records. Following is the code snippet for the class&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService {&lt;br /&gt;
 &lt;br /&gt;
 public Person getPersonObjectFromInputname(String fromPerson) {&lt;br /&gt;
 /*Matches the input string to an existing person object and returns the first person*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public RelationshipType findRelationshipTypeFromInput(String relation) {&lt;br /&gt;
 /*Matches the input string to an existing relationship type*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson, RelationshipType fromPersonRelationship) {&lt;br /&gt;
 /*Function returns the number of people who are related to fromPerson as a fromPersonRelationshiptype */&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson) {&lt;br /&gt;
  /*Function returns the number of people who are related to fromPerson in any way */&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public boolean updateRelativesToNewPerson(Person toPerson, RelationshipType toRelationshipType){&lt;br /&gt;
 /*Updates relations of all relatives of old person to new toRelationshipType of toPerson. If unable to update the records of any of the       &lt;br /&gt;
 relatives, the failure message is logged and the rest of the records are updated*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java ChangeRelationshipsManageController] is the controller. This class contains the functions and attributes required for the view and also acts as an interface between the model and view. Code snippet for this class follows&lt;br /&gt;
 public void manage(ModelMap model) {&lt;br /&gt;
 /*Function to render the view and add attributes that are accessible in the view*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(){&lt;br /&gt;
 /*Function accepts string input of name of person and relationship type and maps it to function in the model that returns the number of  &lt;br /&gt;
 related people*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public String updateRecord(){&lt;br /&gt;
 /*Function accepts string input of name of new person and new relationship type and maps it to the function in the model that updates the  &lt;br /&gt;
 records to reflect the relationships*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The file [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp manage.jsp] is responsible for the view and contains 2 forms. One to search for all the related people and the other to confirm the changes that have to be made with respect to the new person/new relationshiptype or both&lt;br /&gt;
&lt;br /&gt;
===Front Controller Pattern===&lt;br /&gt;
Similar to the MVC pattern, the  [http://en.wikipedia.org/wiki/Front_Controller_pattern Front Controller Pattern] provides a centralized entry point for handling requests.[2]&lt;br /&gt;
The class ChangeRelationshipsManageController (link to source code above) demonstrates this design pattern. As all the requests from the manage page are mapped onto functions in this page, this class is the centralized controller in the design.&lt;br /&gt;
&lt;br /&gt;
===Iterator===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Iterator_pattern Iterator] is a behavioral design pattern used to implement accessing elements of a list quite frequently in the code. A code snippet example would be&lt;br /&gt;
 &lt;br /&gt;
 for(Relationship relationship : allRelatedPeople)&lt;br /&gt;
 {&lt;br /&gt;
 if(toPerson.equals(relationship.getPersonB()))	&lt;br /&gt;
 {&lt;br /&gt;
 areAllUpdatesSuccessful = false;		//as Person1 related to Person1, so avoid by skipping. Boundary case.&lt;br /&gt;
 myLogger.print(&amp;quot;Unable to update record for &amp;quot; + toPerson);&lt;br /&gt;
 continue;&lt;br /&gt;
 }&lt;br /&gt;
 relationship.setPersonA(toPerson);&lt;br /&gt;
 relationship.setRelationshipType(toRelationshipType);&lt;br /&gt;
 personService.saveRelationship(relationship);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Strategy===&lt;br /&gt;
Although, this pattern is not a strong contender for a design pattern used for this code, the [http://en.wikipedia.org/wiki/Strategy_pattern Strategy Pattern] does show itself in the controller function checkPatients()&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(@ModelAttribute(&amp;quot;patientSearch&amp;quot;) PatientSearch patientSearch){&lt;br /&gt;
 if(fromPersonRelation.equals(&amp;quot;All&amp;quot;))	//in case all relations of a person have to be changed call &lt;br /&gt;
 {					// a different overloaded function &lt;br /&gt;
 noOfRelations = changeRelationshipService.numberOfRelationships(fromPersonObject);&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 RelationshipType fromPersonOldRelationshipTypeObject = &lt;br /&gt;
 changeRelationshipService.findRelationshipTypeFromInput(fromPersonRelation);&lt;br /&gt;
 noOfRelations = changeRelationshipService.numberOfRelationships(fromPersonObject, &lt;br /&gt;
 fromPersonOldRelationshipTypeObject);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Depending on the input relationship type selected, two different functions are used to find all the related people. There may not a be a significantly different algorithm used to find the result, but at the database layer, the queries are different.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService class.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
 private void setup()&lt;br /&gt;
 {&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
 this.testCangeRelationshipService = Context.getService(ChangeRelationshipsService.class);&lt;br /&gt;
 this.testPeople = new ArrayList();&lt;br /&gt;
 this.testRelations = new ArrayList();&lt;br /&gt;
 this.testRelationshipTypes = new ArrayList();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :&lt;br /&gt;
 private void createTestPeopleAndRelations()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 testPeople.add(createAndSavePerson(&amp;quot;Person1&amp;quot;, &amp;quot;For1&amp;quot;, &amp;quot;Testing1&amp;quot;, &amp;quot;Male&amp;quot;, 1967, 8,3 ));  &lt;br /&gt;
 testPeople.add(createAndSavePerson(&amp;quot;Person2&amp;quot;, &amp;quot;For2&amp;quot;, &amp;quot;Testing2&amp;quot;, &amp;quot;Male&amp;quot;, 1967, 8,3 ));&lt;br /&gt;
 //some more sample person objects&lt;br /&gt;
 testRelationshipTypes.add(createNewRelationType(&amp;quot;TestRType1&amp;quot;, &amp;quot;TestRType2&amp;quot;));&lt;br /&gt;
 //some more sample relationshiptypes objects&lt;br /&gt;
 testRelations.add(new Relationship(testPeople.get(0), testPeople.get(1), testRelationshipTypes.get(0) ));&lt;br /&gt;
 //some more sample relationships objects&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
 private void deleteDataCreatedForTests() {&lt;br /&gt;
 /*Purge all relations*/&lt;br /&gt;
 /*Purge all relationshipTypes*/&lt;br /&gt;
 /*Purge all persons*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type to the database&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
 public void shouldSetupContext() {&lt;br /&gt;
 assertNotNull(Context.getService(ChangeRelationshipsService.class));&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public void shouldSetupPersonService(){&lt;br /&gt;
 setup();&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
 public void getPersonObjectFromInputnameTest()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 Person testPerson = createAndSavePerson(&amp;quot;Person4&amp;quot;, &amp;quot;For4&amp;quot;, &amp;quot;Testing4&amp;quot;, &amp;quot;Male&amp;quot;, 1909, 12, 12);&lt;br /&gt;
 Person testPerson2 = this.testCangeRelationshipService.getPersonObjectFromInputname(testPerson.getFamilyName());&lt;br /&gt;
 assertNotNull(testPerson2);&lt;br /&gt;
 assertArrayEquals(testPerson2.getFamilyName().toCharArray(), testPerson.getFamilyName().toCharArray());&lt;br /&gt;
 //Some more similar test cases&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
 public void findRelationshipTypeFromInputTest()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 String relationName;&lt;br /&gt;
 List&amp;lt;RelationshipType&amp;gt; testTypes = personService.getAllRelationshipTypes();&lt;br /&gt;
 for(RelationshipType trstype : testTypes)&lt;br /&gt;
 {&lt;br /&gt;
 relationName = trstype.getaIsToB() +  &amp;quot;/&amp;quot; + trstype.getbIsToA();&lt;br /&gt;
 assertNotNull(this.testCangeRelationshipService.findRelationshipTypeFromInput(relationName));&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
 public void numberOfRelationshipGivenPersonAndRelationshipTypeTest()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 createTestPeopleAndRelations();&lt;br /&gt;
 assertEquals(3, this.testCangeRelationshipService.numberOfRelationships(testPeople.get(0), testRelationshipTypes.get(0)));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;br /&gt;
 public void numberOfRelationshipsWhenAllSelected()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 createTestPeopleAndRelations();&lt;br /&gt;
 assertEquals(4, this.testCangeRelationshipService.numberOfRelationships(testPeople.get(0)));&lt;br /&gt;
 assertEquals(0, this.testCangeRelationshipService.numberOfRelationships(testPeople.get(3)));&lt;br /&gt;
 deleteDataCreatedForTests();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit Test : updateRelativesToNewPersonTest()===&lt;br /&gt;
Checks if the required updates are being made in the database correctly&lt;br /&gt;
 public void updateRelativesToNewPersonTest()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 createTestPeopleAndRelations();&lt;br /&gt;
 this.testCangeRelationshipService.numberOfRelationships(testPeople.get(0), testRelationshipTypes.get(1));&lt;br /&gt;
 boolean  updateSuccessful = this.testCangeRelationshipService.updateRelativesToNewPerson(testPeople.get(2), testRelationshipTypes.get(0));&lt;br /&gt;
 assertTrue(updateSuccessful);&lt;br /&gt;
 this.testCangeRelationshipService.numberOfRelationships(testPeople.get(0));&lt;br /&gt;
 updateSuccessful = this.testCangeRelationshipService.updateRelativesToNewPerson(testPeople.get(2), testRelationshipTypes.get(0));&lt;br /&gt;
 assertFalse(updateSuccessful);&lt;br /&gt;
 deleteDataCreatedForTests();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] [http://domino.watson.ibm.com/library/cyberdig.nsf/1e4115aea78b6e7c85256b360066f0d4/696cfba5d4b1e68985256a1e00626e27!OpenDocument Model View Controller]&lt;br /&gt;
&lt;br /&gt;
[2] [http://en.wikipedia.org/wiki/Front_Controller_pattern Front Controller Pattern]&lt;br /&gt;
&lt;br /&gt;
[3] [http://en.wikipedia.org/wiki/Iterator_pattern Iterator]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74361</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74361"/>
		<updated>2013-03-23T14:17:05Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
The module's github readme file can be seen at [https://github.com/ashrayn/openmrs-module-m604/blob/master/README.txt]&lt;br /&gt;
&lt;br /&gt;
Quick Start:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login to OpenMRS with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
Quite a few design patterns were used to design this module. &lt;br /&gt;
===Model View Controller===&lt;br /&gt;
As there was significant UI  and Database functionality, the use of MVC was inevitable [http://domino.watson.ibm.com/library/cyberdig.nsf/1e4115aea78b6e7c85256b360066f0d4/696cfba5d4b1e68985256a1e00626e27!OpenDocument MVC] &lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl ChangeRelationshipServiceImpl] corresponds to the model. This class contains the functions to fire queries to the database and also insert new records/update existing records. Following is the code snippet for the class&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService {&lt;br /&gt;
 &lt;br /&gt;
 public Person getPersonObjectFromInputname(String fromPerson) {&lt;br /&gt;
 /*Matches the input string to an existing person object and returns the first person*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public RelationshipType findRelationshipTypeFromInput(String relation) {&lt;br /&gt;
 /*Matches the input string to an existing relationship type*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson, RelationshipType fromPersonRelationship) {&lt;br /&gt;
 /*Function returns the number of people who are related to fromPerson as a fromPersonRelationshiptype */&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson) {&lt;br /&gt;
  /*Function returns the number of people who are related to fromPerson in any way */&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public boolean updateRelativesToNewPerson(Person toPerson, RelationshipType toRelationshipType){&lt;br /&gt;
 /*Updates relations of all relatives of old person to new toRelationshipType of toPerson. If unable to update the records of any of the       &lt;br /&gt;
 relatives, the failure message is logged and the rest of the records are updated*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java ChangeRelationshipsManageController] is the controller. This class contains the functions and attributes required for the view and also acts as an interface between the model and view. Code snippet for this class follows&lt;br /&gt;
 public void manage(ModelMap model) {&lt;br /&gt;
 /*Function to render the view and add attributes that are accessible in the view*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(){&lt;br /&gt;
 /*Function accepts string input of name of person and relationship type and maps it to function in the model that returns the number of  &lt;br /&gt;
 related people*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public String updateRecord(){&lt;br /&gt;
 /*Function accepts string input of name of new person and new relationship type and maps it to the function in the model that updates the  &lt;br /&gt;
 records to reflect the relationships*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The file [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp manage.jsp] is responsible for the view and contains 2 forms. One to search for all the related people and the other to confirm the changes that have to be made with respect to the new person/new relationshiptype or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Front Controller Pattern===&lt;br /&gt;
Similar to the MVC pattern, the  [http://en.wikipedia.org/wiki/Front_Controller_pattern Front Controller Pattern] provides a centralized entry point for handling requests.[2]&lt;br /&gt;
The class ChangeRelationshipsManageController (link to source code above) demonstrates this design pattern. As all the requests from the manage page are mapped onto functions in this page, this class is the centralized controller in the design.&lt;br /&gt;
&lt;br /&gt;
===Iterator===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Iterator_pattern Iterator] is a behavioral design pattern used to implement accessing elements of a list quite frequently in the code. A code snippet example would be&lt;br /&gt;
 &lt;br /&gt;
 for(Relationship relationship : allRelatedPeople)&lt;br /&gt;
 {&lt;br /&gt;
 if(toPerson.equals(relationship.getPersonB()))	&lt;br /&gt;
 {&lt;br /&gt;
 areAllUpdatesSuccessful = false;		//as Person1 related to Person1, so avoid by skipping. Boundary case.&lt;br /&gt;
 myLogger.print(&amp;quot;Unable to update record for &amp;quot; + toPerson);&lt;br /&gt;
 continue;&lt;br /&gt;
 }&lt;br /&gt;
 relationship.setPersonA(toPerson);&lt;br /&gt;
 relationship.setRelationshipType(toRelationshipType);&lt;br /&gt;
 personService.saveRelationship(relationship);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Strategy===&lt;br /&gt;
Although, this pattern is not a strong contender for a design pattern used for this code, the [http://en.wikipedia.org/wiki/Strategy_pattern Strategy Pattern] does show itself in the controller function checkPatients()&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(@ModelAttribute(&amp;quot;patientSearch&amp;quot;) PatientSearch patientSearch){&lt;br /&gt;
 if(fromPersonRelation.equals(&amp;quot;All&amp;quot;))	//in case all relations of a person have to be changed call &lt;br /&gt;
 {					// a different overloaded function &lt;br /&gt;
 noOfRelations = changeRelationshipService.numberOfRelationships(fromPersonObject);&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 RelationshipType fromPersonOldRelationshipTypeObject = &lt;br /&gt;
 changeRelationshipService.findRelationshipTypeFromInput(fromPersonRelation);&lt;br /&gt;
 noOfRelations = changeRelationshipService.numberOfRelationships(fromPersonObject, &lt;br /&gt;
 fromPersonOldRelationshipTypeObject);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Depending on the input relationship type selected, two different functions are used to find all the related people. There may not a be a significantly different algorithm used to find the result, but at the database layer, the queries are different.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService class.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
 private void setup()&lt;br /&gt;
 {&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
 this.testCangeRelationshipService = Context.getService(ChangeRelationshipsService.class);&lt;br /&gt;
 this.testPeople = new ArrayList();&lt;br /&gt;
 this.testRelations = new ArrayList();&lt;br /&gt;
 this.testRelationshipTypes = new ArrayList();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :&lt;br /&gt;
 private void createTestPeopleAndRelations()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 testPeople.add(createAndSavePerson(&amp;quot;Person1&amp;quot;, &amp;quot;For1&amp;quot;, &amp;quot;Testing1&amp;quot;, &amp;quot;Male&amp;quot;, 1967, 8,3 ));  &lt;br /&gt;
 testPeople.add(createAndSavePerson(&amp;quot;Person2&amp;quot;, &amp;quot;For2&amp;quot;, &amp;quot;Testing2&amp;quot;, &amp;quot;Male&amp;quot;, 1967, 8,3 ));&lt;br /&gt;
 //some more sample person objects&lt;br /&gt;
 testRelationshipTypes.add(createNewRelationType(&amp;quot;TestRType1&amp;quot;, &amp;quot;TestRType2&amp;quot;));&lt;br /&gt;
 //some more sample relationshiptypes objects&lt;br /&gt;
 testRelations.add(new Relationship(testPeople.get(0), testPeople.get(1), testRelationshipTypes.get(0) ));&lt;br /&gt;
 //some more sample relationships objects&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
 private void deleteDataCreatedForTests() {&lt;br /&gt;
 /*Purge all relations*/&lt;br /&gt;
 /*Purge all relationshipTypes*/&lt;br /&gt;
 /*Purge all persons*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type to the database&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
 public void shouldSetupContext() {&lt;br /&gt;
 assertNotNull(Context.getService(ChangeRelationshipsService.class));&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public void shouldSetupPersonService(){&lt;br /&gt;
 setup();&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
 public void getPersonObjectFromInputnameTest()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 Person testPerson = createAndSavePerson(&amp;quot;Person4&amp;quot;, &amp;quot;For4&amp;quot;, &amp;quot;Testing4&amp;quot;, &amp;quot;Male&amp;quot;, 1909, 12, 12);&lt;br /&gt;
 Person testPerson2 = this.testCangeRelationshipService.getPersonObjectFromInputname(testPerson.getFamilyName());&lt;br /&gt;
 assertNotNull(testPerson2);&lt;br /&gt;
 assertArrayEquals(testPerson2.getFamilyName().toCharArray(), testPerson.getFamilyName().toCharArray());&lt;br /&gt;
 //Some more similar test cases&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
 public void findRelationshipTypeFromInputTest()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 String relationName;&lt;br /&gt;
 List&amp;lt;RelationshipType&amp;gt; testTypes = personService.getAllRelationshipTypes();&lt;br /&gt;
 for(RelationshipType trstype : testTypes)&lt;br /&gt;
 {&lt;br /&gt;
 relationName = trstype.getaIsToB() +  &amp;quot;/&amp;quot; + trstype.getbIsToA();&lt;br /&gt;
 assertNotNull(this.testCangeRelationshipService.findRelationshipTypeFromInput(relationName));&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
 public void numberOfRelationshipGivenPersonAndRelationshipTypeTest()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 createTestPeopleAndRelations();&lt;br /&gt;
 assertEquals(3, this.testCangeRelationshipService.numberOfRelationships(testPeople.get(0), testRelationshipTypes.get(0)));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;br /&gt;
 public void numberOfRelationshipsWhenAllSelected()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 createTestPeopleAndRelations();&lt;br /&gt;
 assertEquals(4, this.testCangeRelationshipService.numberOfRelationships(testPeople.get(0)));&lt;br /&gt;
 assertEquals(0, this.testCangeRelationshipService.numberOfRelationships(testPeople.get(3)));&lt;br /&gt;
 deleteDataCreatedForTests();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit Test : updateRelativesToNewPersonTest()===&lt;br /&gt;
Checks if the required updates are being made in the database correctly&lt;br /&gt;
 public void updateRelativesToNewPersonTest()&lt;br /&gt;
 {&lt;br /&gt;
 setup();&lt;br /&gt;
 createTestPeopleAndRelations();&lt;br /&gt;
 this.testCangeRelationshipService.numberOfRelationships(testPeople.get(0), testRelationshipTypes.get(1));&lt;br /&gt;
 boolean  updateSuccessful = this.testCangeRelationshipService.updateRelativesToNewPerson(testPeople.get(2), testRelationshipTypes.get(0));&lt;br /&gt;
 assertTrue(updateSuccessful);&lt;br /&gt;
 this.testCangeRelationshipService.numberOfRelationships(testPeople.get(0));&lt;br /&gt;
 updateSuccessful = this.testCangeRelationshipService.updateRelativesToNewPerson(testPeople.get(2), testRelationshipTypes.get(0));&lt;br /&gt;
 assertFalse(updateSuccessful);&lt;br /&gt;
 deleteDataCreatedForTests();&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] [http://domino.watson.ibm.com/library/cyberdig.nsf/1e4115aea78b6e7c85256b360066f0d4/696cfba5d4b1e68985256a1e00626e27!OpenDocument Model View Controller]&lt;br /&gt;
&lt;br /&gt;
[2] [http://en.wikipedia.org/wiki/Front_Controller_pattern Front Controller Pattern]&lt;br /&gt;
&lt;br /&gt;
[3] [http://en.wikipedia.org/wiki/Iterator_pattern Iterator]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74355</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74355"/>
		<updated>2013-03-22T04:40:32Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
Quite a few design patterns were used to design this module. &lt;br /&gt;
===Model View Controller===&lt;br /&gt;
As there was significant UI  and Database functionality, the use of MVC was inevitable [http://domino.watson.ibm.com/library/cyberdig.nsf/1e4115aea78b6e7c85256b360066f0d4/696cfba5d4b1e68985256a1e00626e27!OpenDocument MVC] &lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl ChangeRelationshipServiceImpl] corresponds to the model. This class contains the functions to fire queries to the database and also insert new records/update existing records. Following is the code snippet for the class&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService {&lt;br /&gt;
 &lt;br /&gt;
 public Person getPersonObjectFromInputname(String fromPerson) {&lt;br /&gt;
 /*Matches the input string to an existing person object and returns the first person*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public RelationshipType findRelationshipTypeFromInput(String relation) {&lt;br /&gt;
 /*Matches the input string to an existing relationship type*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson, RelationshipType fromPersonRelationship) {&lt;br /&gt;
 /*Function returns the number of people who are related to fromPerson as a fromPersonRelationshiptype */&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson) {&lt;br /&gt;
  /*Function returns the number of people who are related to fromPerson in any way */&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public boolean updateRelativesToNewPerson(Person toPerson, RelationshipType toRelationshipType){&lt;br /&gt;
 /*Updates relations of all relatives of old person to new toRelationshipType of toPerson. If unable to update the records of any of the       &lt;br /&gt;
 relatives, the failure message is logged and the rest of the records are updated*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java ChangeRelationshipsManageController] is the controller. This class contains the functions and attributes required for the view and also acts as an interface between the model and view. Code snippet for this class follows&lt;br /&gt;
 public void manage(ModelMap model) {&lt;br /&gt;
 /*Function to render the view and add attributes that are accessible in the view*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(){&lt;br /&gt;
 /*Function accepts string input of name of person and relationship type and maps it to function in the model that returns the number of  &lt;br /&gt;
 related people*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public String updateRecord(){&lt;br /&gt;
 /*Function accepts string input of name of new person and new relationship type and maps it to the function in the model that updates the  &lt;br /&gt;
 records to reflect the relationships*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The file [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp manage.jsp] is responsible for the view and contains 2 forms. One to search for all the related people and the other to confirm the changes that have to be made with respect to the new person/new relationshiptype or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Front Controller Pattern===&lt;br /&gt;
Similar to the MVC pattern, the  [http://en.wikipedia.org/wiki/Front_Controller_pattern Front Controller Pattern] provides a centralized entry point for handling requests.[2]&lt;br /&gt;
The class ChangeRelationshipsManageController (link to source code above) demonstrates this design pattern. As all the requests from the manage page are mapped onto functions in this page, this class is the centralized controller in the design.&lt;br /&gt;
&lt;br /&gt;
===Iterator===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Iterator_pattern Iterator] is a behavioral design pattern used to implement accessing elements of a list quite frequently in the code. A code snippet example would be&lt;br /&gt;
 &lt;br /&gt;
 for(Relationship relationship : allRelatedPeople)&lt;br /&gt;
 {&lt;br /&gt;
 if(toPerson.equals(relationship.getPersonB()))	&lt;br /&gt;
 {&lt;br /&gt;
 areAllUpdatesSuccessful = false;		//as Person1 related to Person1, so avoid by skipping. Boundary case.&lt;br /&gt;
 myLogger.print(&amp;quot;Unable to update record for &amp;quot; + toPerson);&lt;br /&gt;
 continue;&lt;br /&gt;
 }&lt;br /&gt;
 relationship.setPersonA(toPerson);&lt;br /&gt;
 relationship.setRelationshipType(toRelationshipType);&lt;br /&gt;
 personService.saveRelationship(relationship);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===Strategy===&lt;br /&gt;
Although, this pattern is not a strong contender for a design pattern used for this code, the [http://en.wikipedia.org/wiki/Strategy_pattern Strategy Pattern] does show itself in the controller function checkPatients()&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(@ModelAttribute(&amp;quot;patientSearch&amp;quot;) PatientSearch patientSearch){&lt;br /&gt;
 if(fromPersonRelation.equals(&amp;quot;All&amp;quot;))	//in case all relations of a person have to be changed call &lt;br /&gt;
 {					// a different overloaded function &lt;br /&gt;
 noOfRelations = changeRelationshipService.numberOfRelationships(fromPersonObject);&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
 RelationshipType fromPersonOldRelationshipTypeObject = &lt;br /&gt;
 changeRelationshipService.findRelationshipTypeFromInput(fromPersonRelation);&lt;br /&gt;
 noOfRelations = changeRelationshipService.numberOfRelationships(fromPersonObject, &lt;br /&gt;
 fromPersonOldRelationshipTypeObject);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Depending on the input relationship type selected, two different functions are used to find all the related people. There may not a be a significantly different algorithm used to find the result, but at the database layer, the queries are different.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService class.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type tothe database&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] [http://domino.watson.ibm.com/library/cyberdig.nsf/1e4115aea78b6e7c85256b360066f0d4/696cfba5d4b1e68985256a1e00626e27!OpenDocument Model View Controller]&lt;br /&gt;
[2] [http://en.wikipedia.org/wiki/Front_Controller_pattern Front Controller Pattern]&lt;br /&gt;
[3] [http://en.wikipedia.org/wiki/Iterator_pattern Iterator]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74354</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74354"/>
		<updated>2013-03-22T04:28:41Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
Quite a few design patterns were used to design this module. &lt;br /&gt;
===Model View Controller===&lt;br /&gt;
As there was significant UI  and Database functionality, the use of MVC was inevitable [http://domino.watson.ibm.com/library/cyberdig.nsf/1e4115aea78b6e7c85256b360066f0d4/696cfba5d4b1e68985256a1e00626e27!OpenDocument MVC] &lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl ChangeRelationshipServiceImpl] corresponds to the model. This class contains the functions to fire queries to the database and also insert new records/update existing records. Following is the code snippet for the class&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService {&lt;br /&gt;
 &lt;br /&gt;
 public Person getPersonObjectFromInputname(String fromPerson) {&lt;br /&gt;
 /*Matches the input string to an existing person object and returns the first person*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public RelationshipType findRelationshipTypeFromInput(String relation) {&lt;br /&gt;
 /*Matches the input string to an existing relationship type*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson, RelationshipType fromPersonRelationship) {&lt;br /&gt;
 /*Function returns the number of people who are related to fromPerson as a fromPersonRelationshiptype */&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson) {&lt;br /&gt;
  /*Function returns the number of people who are related to fromPerson in any way */&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public boolean updateRelativesToNewPerson(Person toPerson, RelationshipType toRelationshipType){&lt;br /&gt;
 /*Updates relations of all relatives of old person to new toRelationshipType of toPerson. If unable to update the records of any of the       &lt;br /&gt;
 relatives, the failure message is logged and the rest of the records are updated*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java ChangeRelationshipsManageController] is the controller. This class contains the functions and attributes required for the view and also acts as an interface between the model and view. Code snippet for this class follows&lt;br /&gt;
 public void manage(ModelMap model) {&lt;br /&gt;
 /*Function to render the view and add attributes that are accessible in the view*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(){&lt;br /&gt;
 /*Function accepts string input of name of person and relationship type and maps it to function in the model that returns the number of  &lt;br /&gt;
 related people*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public String updateRecord(){&lt;br /&gt;
 /*Function accepts string input of name of new person and new relationship type and maps it to the function in the model that updates the  &lt;br /&gt;
 records to reflect the relationships*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The file [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp manage.jsp] is responsible for the view and contains 2 forms. One to search for all the related people and the other to confirm the changes that have to be made with respect to the new person/new relationshiptype or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Front Controller Pattern===&lt;br /&gt;
Similar to the MVC pattern, the  [http://en.wikipedia.org/wiki/Front_Controller_pattern Front Controller Pattern] provides a centralized entry point for handling requests.[2]&lt;br /&gt;
The class ChangeRelationshipsManageController (link to source code above) demonstrates this design pattern. As all the requests from the manage page are mapped onto functions in this page, this class is the centralized controller in the design.&lt;br /&gt;
&lt;br /&gt;
===Iterator===&lt;br /&gt;
[http://en.wikipedia.org/wiki/Iterator_pattern Iterator] is a behavioral design pattern used to implement accessing elements of a list quite frequently in the code. A code snippet example would be&lt;br /&gt;
 &lt;br /&gt;
 for(Relationship relationship : allRelatedPeople)&lt;br /&gt;
 {&lt;br /&gt;
 if(toPerson.equals(relationship.getPersonB()))	&lt;br /&gt;
 {&lt;br /&gt;
 areAllUpdatesSuccessful = false;		//as Person1 related to Person1, so avoid by skipping. Boundary case.&lt;br /&gt;
 myLogger.print(&amp;quot;Unable to update record for &amp;quot; + toPerson);&lt;br /&gt;
 continue;&lt;br /&gt;
 }&lt;br /&gt;
 relationship.setPersonA(toPerson);&lt;br /&gt;
 relationship.setRelationshipType(toRelationshipType);&lt;br /&gt;
 personService.saveRelationship(relationship);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService class.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type tothe database&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
[1] [http://domino.watson.ibm.com/library/cyberdig.nsf/1e4115aea78b6e7c85256b360066f0d4/696cfba5d4b1e68985256a1e00626e27!OpenDocument Model View Controller]&lt;br /&gt;
[2] [http://en.wikipedia.org/wiki/Front_Controller_pattern Front Controller Pattern]&lt;br /&gt;
[3] [http://en.wikipedia.org/wiki/Iterator_pattern Iterator]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74353</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74353"/>
		<updated>2013-03-22T03:49:18Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
Quite a few design patterns were used to design this module. &lt;br /&gt;
===Model View Controller===&lt;br /&gt;
As there was significant UI  and Database functionality, the use of the MVC architecture is justified&lt;br /&gt;
The class [ https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl ChangeRelationshipServiceImpl] corresponds to the model. This class contains the functions to fire queries to the database and also insert new records/update existing records. Following is the code snippet for the class&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService {&lt;br /&gt;
 &lt;br /&gt;
 public Person getPersonObjectFromInputname(String fromPerson) {&lt;br /&gt;
 /*Matches the input string to an existing person object and returns the first person*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public RelationshipType findRelationshipTypeFromInput(String relation) {&lt;br /&gt;
 /*Matches the input string to an existing relationship type*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson, RelationshipType fromPersonRelationship) {&lt;br /&gt;
 /*Function returns the number of people who are related to fromPerson as a fromPersonRelationshiptype */&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson) {&lt;br /&gt;
  /*Function returns the number of people who are related to fromPerson in any way */&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public boolean updateRelativesToNewPerson(Person toPerson, RelationshipType toRelationshipType){&lt;br /&gt;
 /*Updates relations of all relatives of old person to new toRelationshipType of toPerson. If unable to update the records of any of the       &lt;br /&gt;
 relatives, the failure message is logged and the rest of the records are updated*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The class [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java ChangeRelationshipsManageController] is the controller. This class contains the functions and attributes required for the view and also acts as an interface between the model and view. Code snippet for this class follows&lt;br /&gt;
 public void manage(ModelMap model) {&lt;br /&gt;
 /*Function to render the view and add attributes that are accessible in the view*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(){&lt;br /&gt;
 /*Function accepts string input of name of person and relationship type and maps it to function in the model that returns the number of  &lt;br /&gt;
 related people*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public String updateRecord(){&lt;br /&gt;
 /*Function accepts string input of name of new person and new relationship type and maps it to the function in the model that updates the  &lt;br /&gt;
 records to reflect the relationships*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The file [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp manage.jsp] is responsible for the view and contains 2 forms. One to search for all the related people and the other to confirm the changes that have to be made with respect to the new person/new relationshiptype or both&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService class.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type tothe database&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74352</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74352"/>
		<updated>2013-03-22T03:44:49Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Design Patterns==&lt;br /&gt;
Quite a few design patterns were used to design this module. &lt;br /&gt;
===Model View Controller===&lt;br /&gt;
As there was significant UI  and Database functionality, the use of the MVC architecture is justified&lt;br /&gt;
The class ChangeRelationshipServiceImpl corresponds to the model. This class contains the functions to fire queries to the database and also insert new records/update existing records. Following is the code snippet for the class&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService {&lt;br /&gt;
 &lt;br /&gt;
 public Person getPersonObjectFromInputname(String fromPerson) {&lt;br /&gt;
 /*Matches the input string to an existing person object and returns the first person*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public RelationshipType findRelationshipTypeFromInput(String relation) {&lt;br /&gt;
 /*Matches the input string to an existing relationship type*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson, RelationshipType fromPersonRelationship) {&lt;br /&gt;
 /*Function returns the number of people who are related to fromPerson as a fromPersonRelationshiptype */&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public int numberOfRelationships(Person fromPerson) {&lt;br /&gt;
  /*Function returns the number of people who are related to fromPerson in any way */&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public boolean updateRelativesToNewPerson(Person toPerson, RelationshipType toRelationshipType){&lt;br /&gt;
 /*Updates relations of all relatives of old person to new toRelationshipType of toPerson. If unable to update the records of any of the       &lt;br /&gt;
 relatives, the failure message is logged and the rest of the records are updated*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The class ChangeRelationshipsManageController is the controller. This class contains the functions and attributes required for the view and also acts as an interface between the model and view. Code snippet for this class follows&lt;br /&gt;
 public void manage(ModelMap model) {&lt;br /&gt;
 /*Function to render the view and add attributes that are accessible in the view*/&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 public String checkPatients(){&lt;br /&gt;
 /*Function accepts string input of name of person and relationship type and maps it to function in the model that returns the number of  &lt;br /&gt;
 related people*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 public String updateRecord(){&lt;br /&gt;
 /*Function accepts string input of name of new person and new relationship type and maps it to the function in the model that updates the  &lt;br /&gt;
 records to reflect the relationships*/&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The file manage.jsp is responsible for the view and contains 2 forms. One to search for all the related people and the other to confirm the changes that have to be made with respect to the new person/new relationshiptype or both&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService class.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type tothe database&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74351</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74351"/>
		<updated>2013-03-21T22:09:13Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService class.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type tothe database&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74350</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74350"/>
		<updated>2013-03-21T22:07:58Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService class.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
 this.testCangeRelationshipService = Context.getService(ChangeRelationshipsService.class);&lt;br /&gt;
 this.testPeople = new ArrayList();&lt;br /&gt;
 this.testRelations = new ArrayList();&lt;br /&gt;
 this.testRelationshipTypes = new ArrayList();&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :  &lt;br /&gt;
 createTestPeopleAndRelations(){&lt;br /&gt;
 testPeople.add(createAndSavePerson(&amp;quot;Person5&amp;quot;, &amp;quot;For5&amp;quot;, &amp;quot;Testing5&amp;quot;, &amp;quot;Male&amp;quot;, 1967, 8,3 ));&lt;br /&gt;
 testRelationshipTypes.add(createNewRelationType(&amp;quot;TestRType1&amp;quot;, &amp;quot;TestRType2&amp;quot;));&lt;br /&gt;
 testRelations.add(new Relationship(testPeople.get(0), testPeople.get(1), testRelationshipTypes.get(0) ));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
 deleteDataCreatedForTests(){&lt;br /&gt;
 personService.purgeRelationship(rs);&lt;br /&gt;
 personService.purgeRelationshipType(rt);&lt;br /&gt;
 personService.purgePerson(p);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type tothe database&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
 public void shouldSetupContext() {&lt;br /&gt;
		assertNotNull(Context.getService(ChangeRelationshipsService.class));&lt;br /&gt;
	}&lt;br /&gt;
 public void shouldSetupPersonService(){&lt;br /&gt;
		setup();&lt;br /&gt;
		assertNotNull(personService);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74349</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74349"/>
		<updated>2013-03-21T21:46:30Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService function.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
 this.testCangeRelationshipService = Context.getService(ChangeRelationshipsService.class);&lt;br /&gt;
 this.testPeople = new ArrayList();&lt;br /&gt;
 this.testRelations = new ArrayList();&lt;br /&gt;
 this.testRelationshipTypes = new ArrayList();&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :  &lt;br /&gt;
 createTestPeopleAndRelations(){&lt;br /&gt;
 testPeople.add(createAndSavePerson(&amp;quot;Person5&amp;quot;, &amp;quot;For5&amp;quot;, &amp;quot;Testing5&amp;quot;, &amp;quot;Male&amp;quot;, 1967, 8,3 ));&lt;br /&gt;
 testRelationshipTypes.add(createNewRelationType(&amp;quot;TestRType1&amp;quot;, &amp;quot;TestRType2&amp;quot;));&lt;br /&gt;
 testRelations.add(new Relationship(testPeople.get(0), testPeople.get(1), testRelationshipTypes.get(0) ));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
 deleteDataCreatedForTests(){&lt;br /&gt;
 personService.purgeRelationship(rs);&lt;br /&gt;
 personService.purgeRelationshipType(rt);&lt;br /&gt;
 personService.purgePerson(p);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type tothe database&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
&lt;br /&gt;
===Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
&lt;br /&gt;
===Unit test : findRelationshipTypeFromInputTest()=== &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Tests wether the function numberOfRelationships() returns the right number of related people given the name of a person and the relationship type.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipsWhenAllSelected()===&lt;br /&gt;
In case the user chose to change all the relationships for a given person, this test case checks to see if the function numberOfRelationships() returns the right number of people related to the given person in any possible way.&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74348</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74348"/>
		<updated>2013-03-21T21:25:26Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
The framework used here for testing is [http://junit.org/ JUnit4]&lt;br /&gt;
All the code for the test functions are at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/test/java/org/openmrs/module/changerelationships/api/ChangeRelationshipsServiceTest.java ChangeRelationshipsServiceTest.java]&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService function.&lt;br /&gt;
===Setup()===&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
 this.testCangeRelationshipService = Context.getService(ChangeRelationshipsService.class);&lt;br /&gt;
 this.testPeople = new ArrayList();&lt;br /&gt;
 this.testRelations = new ArrayList();&lt;br /&gt;
 this.testRelationshipTypes = new ArrayList();&lt;br /&gt;
===Test Data===&lt;br /&gt;
The createTestPeopleAndRelations() functions is similar to the setup function, as it too sets up the background data required for some of the testing, but since not all of the unit tests require a sample data, they are in a separate function and only those functions that require the data call them. Code snippet for the function :  &lt;br /&gt;
 createTestPeopleAndRelations(){&lt;br /&gt;
 testPeople.add(createAndSavePerson(&amp;quot;Person5&amp;quot;, &amp;quot;For5&amp;quot;, &amp;quot;Testing5&amp;quot;, &amp;quot;Male&amp;quot;, 1967, 8,3 ));&lt;br /&gt;
 testRelationshipTypes.add(createNewRelationType(&amp;quot;TestRType1&amp;quot;, &amp;quot;TestRType2&amp;quot;));&lt;br /&gt;
 testRelations.add(new Relationship(testPeople.get(0), testPeople.get(1), testRelationshipTypes.get(0) ));&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Similarly the function deleteDataCreatedForTests() is a cleanup function that removes all the data created specifically for the tests. Code snippet for the function : &lt;br /&gt;
 deleteDataCreatedForTests(){&lt;br /&gt;
 personService.purgeRelationship(rs);&lt;br /&gt;
 personService.purgeRelationshipType(rt);&lt;br /&gt;
 personService.purgePerson(p);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The functions createNewRelationType() and createAndSavePerson() are helper functions for the test data setup functions mentioned above. The createAndSavePerson() saves each person to the database while the  createNewRelationType() function saves each new relationship type tothe database&lt;br /&gt;
&lt;br /&gt;
===Unit test : shouldSetupContext() and shouldSetupPersonService()===&lt;br /&gt;
Makes sure that the service objects are initialized and not null.&lt;br /&gt;
&lt;br /&gt;
==Unit test : getPersonObjectFromInputnameTest ===&lt;br /&gt;
Asserts that the function getPersonObjectFromInputname() returns exactly one person in case a record matching the given name is found, else returns a record not found error&lt;br /&gt;
&lt;br /&gt;
==Unit test : findRelationshipTypeFromInputTest() === &lt;br /&gt;
Asserts that the function findRelationshipTypeFromInputTest() returns the relationship type in case a record matching the given type name is found, else returns a record not found error.&lt;br /&gt;
&lt;br /&gt;
===unit Test : numberOfRelationshipGivenPersonAndRelationshipTypeTest()===&lt;br /&gt;
Asserts&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74347</id>
		<title>CSC/ECE 517 Spring 2013/OSS M604</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/OSS_M604&amp;diff=74347"/>
		<updated>2013-03-21T20:52:49Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=OpenMRS Change Patient Relationships=&lt;br /&gt;
&lt;br /&gt;
== README ==&lt;br /&gt;
The design document for the project can be found at [https://wiki.openmrs.org/display/projects/Change+relationship+for+multiple+patients+at+once]&lt;br /&gt;
&lt;br /&gt;
The project is currently hosted at a long term VCL image found at [http://152.46.17.15:8081/openmrs-standalone/index.htm] &lt;br /&gt;
&lt;br /&gt;
The code for our module is hosted on github at [https://github.com/ashrayn/openmrs-module-m604]&lt;br /&gt;
&lt;br /&gt;
To Use:&lt;br /&gt;
&amp;lt;ol&amp;gt;&amp;lt;li&amp;gt;Login with user:Admin password:Admin123.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click the 'Administration' button in the top-right corner.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;In the bottom-right corner, under 'patients' there should be a link for &amp;quot;change patient relationships&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Click on the 'change patient relationships' link&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The content of the change patient relationships module should be displayed.&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To see a list of possible patients, it may be useful to open a separate tab with the 'Find/Create Patient&amp;quot; menu from the main menu bar.&lt;br /&gt;
&lt;br /&gt;
==Writing Exercise 2==&lt;br /&gt;
===Design Overview of the Module===&lt;br /&gt;
OpenMRS modules utilize a modified Spring MVC framework [http://en.wikipedia.org/wiki/Spring_Framework].  The skeleton for the module is first generated using convenient maven[http://maven.apache.org/] artifacts provided here [https://wiki.openmrs.org/display/docs/Creating+Your+First+Module].&lt;br /&gt;
&lt;br /&gt;
The 'change patient relationships' module utilizes 5 basic files.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The main page is a .jsp [http://en.wikipedia.org/wiki/JavaServer_Pages] page, the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/webapp/manage.jsp].&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;This .jsp page is linked to a spring annotated controller [http://javapapers.com/spring/spring-annotation-based-controllers/], the code can be found at [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/web/controller/ChangeRelationshipsManageController.java].  The annotated controller maps the manage.jsp form actions using the '@RequestMapping' annotations.  This pattern can be observed by viewing the manage.jsp code and comparing the &amp;lt;form&amp;gt; tags to the @RequestMapping annotations in the java code.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li/&amp;gt;&amp;lt;li&amp;gt;The controller along with the spring framework link the form actions from the 'manage.jsp' page to java objects defined in the following .java files.  [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/PatientSearch.java] and [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/omod/src/main/java/org/openmrs/module/changerelationships/UpdateRecord.java]&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;The module utilizes OpenMRS's services infrastructure to create services with the following code [https://github.com/ashrayn/openmrs-module-m604/blob/master/changerelationships/api/src/main/java/org/openmrs/module/changerelationships/api/impl/ChangeRelationshipsServiceImpl.java].  The services found within this class are retrieved from the OpenMRS context object inside of the above controller code (#2). The ChangePatientRelationshipsServiceImpl.java class utilizes OpenMRS database APIs [https://wiki.openmrs.org/display/docs/API] to actually change the patient data in the OpenMRS database.  &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The entire module is packaged in an OpenMRS .omod file using maven and pre-created packaging scripts. The .omod file can be found here [https://github.com/ashrayn/openmrs-module-m604/tree/master/changerelationships/omod/target] and installed into any OpenMRS server using the 'Administration'&amp;gt;Manage modules page.&lt;br /&gt;
&lt;br /&gt;
===Object-Oriented Design Principles Used===&lt;br /&gt;
&amp;lt;b&amp;gt;Encapsulation&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There were several instances of encapsulation used through out our implementation code in the OpenMRS module. For example, to get access to relationships between people in the database in OpenMRS, we first had to use the Context class to get a PersonService object type and then use that object type to access a list of relationships:&lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
Here, getPersonService() is a static method in class Context that doesn't require instantiating a Context object to call the method. getPersonService() can be directly used as a class method without having to know the details of how the method has been implemented and designed.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Another example is making helper methods and instance variables private. &lt;br /&gt;
 private Person getPersonOut(List&amp;lt;Relationship&amp;gt; relationshipList, String nameOut)&lt;br /&gt;
This is a helper method to the changePatientRelationships() method that helps locate the Person object for updating the patient relationship. As it is not directly used in the manage.jsp page for the user-interface, it is made private to restrict access to it.&lt;br /&gt;
&lt;br /&gt;
 private ChangeRelationshipsDAO dao;&lt;br /&gt;
 private List&amp;lt;Person&amp;gt; people;&lt;br /&gt;
 private List&amp;lt;Relationship&amp;gt; allRelatedPeople;&lt;br /&gt;
 private List&amp;lt;RelationshipType&amp;gt; existingRelationshipTypes;&lt;br /&gt;
 private int noOfRelatedPeople;&lt;br /&gt;
These instance variables are also made private in our module class to prevent the potential corruption of data if they were to be accessed publicly.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;Open-Closed Principle&amp;lt;/b&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
In the OpenMRS module, existing classes that had already been tested were not modified, which exemplifies the open-closed principle [http://en.wikipedia.org/wiki/Open/closed_principle]. This module is an extension of the OpenMRS functionality. Our ChangeRelationshipsServiceImpl class is an added class to specifically add the functionality of being able to update the relationships of several patients at one time. Specifically, in our the ChangeRelationshipServiceImpl, we extend the class BaseOpenmrsService to implement the new functionality:&lt;br /&gt;
 public class ChangeRelationshipsServiceImpl extends BaseOpenmrsService implements ChangeRelationshipsService&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Testing===&lt;br /&gt;
The framework used here for testing is JUnit4[http://junit.org/]&lt;br /&gt;
The test class consists of simple unit tests to test the working of each function used in the ChangeRelationshipService function.&lt;br /&gt;
The setup() function is the one responsible for setting up the background before testing all the functions. It initializes all the objects used for testing later. The code for setup() is as &lt;br /&gt;
 personService = Context.getPersonService();&lt;br /&gt;
 this.testCangeRelationshipService = Context.getService(ChangeRelationshipsService.class);&lt;br /&gt;
 this.testPeople = new ArrayList();&lt;br /&gt;
 this.testRelations = new ArrayList();&lt;br /&gt;
 this.testRelationshipTypes = new ArrayList();&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73029</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73029"/>
		<updated>2013-02-15T05:41:54Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
[http://expressionflow.com/2007/04/14/reusing-code-by-inheritance/ Image from Expression Flow]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance(1)===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning(3)] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation(2)] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
===Object Creation(1)===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules(5)===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects(5)===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress(4)===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object(5)===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based(5)===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming](5)===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not(4)===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way(5)===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances(5)===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Which is the better approach'''(5)==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  (1)Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) (2)Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) (3)Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr (4)Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop (5)advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html (6)Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73028</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73028"/>
		<updated>2013-02-15T05:38:07Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
[http://expressionflow.com/2007/04/14/reusing-code-by-inheritance/ Image from Expression Flow]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
===Object Creation[]===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Which is the better approach'''==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  (1)Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) (2)Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) (3)Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr (4)Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop (5)advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html (6)Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73027</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73027"/>
		<updated>2013-02-15T05:37:15Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
[http://expressionflow.com/2007/04/14/reusing-code-by-inheritance/ Image from Expression Flow]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
===Object Creation[]===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Which is the better approach'''==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  [1/]Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) [2]Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) [3]Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr [4]Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop [5]advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html [6]Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73026</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73026"/>
		<updated>2013-02-15T05:36:47Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
[http://expressionflow.com/2007/04/14/reusing-code-by-inheritance/ Image from Expression Flow]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
===Object Creation[]===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Which is the better approach'''==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  [1]Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) [2]Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) [3]Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr [4]Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop [5]advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html [6]Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73025</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73025"/>
		<updated>2013-02-15T05:34:44Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
[http://expressionflow.com/2007/04/14/reusing-code-by-inheritance/ Image from Expression Flow]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
[[===Object Creation===]]&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Which is the better approach'''==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73024</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73024"/>
		<updated>2013-02-15T05:30:56Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
                               [http://expressionflow.com/2007/04/14/reusing-code-by-inheritance/ Image from Expression Flow]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Which is the better approach'''==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73023</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73023"/>
		<updated>2013-02-15T05:30:20Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
[http://expressionflow.com/2007/04/14/reusing-code-by-inheritance/ Image from Expression Flow|center ]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Which is the better approach'''==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73022</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73022"/>
		<updated>2013-02-15T05:21:29Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Which is the better approach'''==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
=='''References'''==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73021</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73021"/>
		<updated>2013-02-15T05:20:29Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=='''Inheritance'''==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Means of achieving inheritance'''==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=='''Classical Inheritance v/s Prototype based inheritance'''==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73020</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73020"/>
		<updated>2013-02-15T04:59:16Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73019</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73019"/>
		<updated>2013-02-15T04:56:48Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [ http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [http://www.go4expert.com/articles/object-cloning-java-t5424  cloning-logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73018</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73018"/>
		<updated>2013-02-15T04:55:32Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [ http://en.wikipedia.org/wiki/Cloning_(programming) clone] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [ http://www.go4expert.com/articles/object-cloning-java-t5424 cloning logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73017</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73017"/>
		<updated>2013-02-15T04:53:52Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to [http://en.wikipedia.org/wiki/Cloning_(programming) &amp;quot;clone&amp;quot;] an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex [ http://www.go4expert.com/articles/object-cloning-java-t5424/ cloning logic] for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a [http://en.wikipedia.org/wiki/Functional_programming &amp;quot;functional&amp;quot; style of programming]===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support [http://c2.com/cgi/wiki?DynamicTyping dynamic typing], otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs /[http://c2.com/cgi/wiki?WhatIsRefactoring refactoring] tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers [http://c2.com/cgi/wiki?StaticTyping static typing] wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
 For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical   &lt;br /&gt;
 approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would &lt;br /&gt;
 seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since  &lt;br /&gt;
 each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it &lt;br /&gt;
 would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73011</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=73011"/>
		<updated>2013-02-15T04:19:36Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr Work by students from previous semesters]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html Prototype based inheritance in javascript]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72273</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72273"/>
		<updated>2013-02-09T03:43:01Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
 [http://javascript.crockford.com/prototypal.html http://javascript.crockford.com/prototypal.html]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72271</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72271"/>
		<updated>2013-02-09T03:36:28Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
 For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its  &lt;br /&gt;
 properties even though it inherits from the same.&lt;br /&gt;
 However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be &lt;br /&gt;
 defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the &lt;br /&gt;
 medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
 Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps &lt;br /&gt;
 object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state   &lt;br /&gt;
 from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
 For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a &lt;br /&gt;
 new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class   &lt;br /&gt;
 based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone  &lt;br /&gt;
 the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
 Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
 This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be  &lt;br /&gt;
 embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate &lt;br /&gt;
 function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
 In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman &lt;br /&gt;
 basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler &lt;br /&gt;
 error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
&lt;br /&gt;
 Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each  &lt;br /&gt;
 of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. &lt;br /&gt;
 This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the  &lt;br /&gt;
 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
 Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent  &lt;br /&gt;
 out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member &lt;br /&gt;
 of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning &lt;br /&gt;
 occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
[http://javascript.crockford.com/prototypal.html http://javascript.crockford.com/prototypal.html]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72270</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72270"/>
		<updated>2013-02-09T03:33:20Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
===Classical Inheritance===&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype Based Inheritance===&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
 In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique  &lt;br /&gt;
 behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for  &lt;br /&gt;
 the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit &lt;br /&gt;
 from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in &lt;br /&gt;
 prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
[http://javascript.crockford.com/prototypal.html http://javascript.crockford.com/prototypal.html]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72269</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72269"/>
		<updated>2013-02-09T03:29:55Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;br /&gt;
[http://javascript.crockford.com/prototypal.html http://javascript.crockford.com/prototypal.html]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72268</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72268"/>
		<updated>2013-02-09T03:28:43Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Using Preexisting modules===&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Support for one-of-a-kind objects===&lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Elimination of meta-regress===&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
===Transfer of state information on extending the functionality of an object===&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based===&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming===&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Prototype based inheritance requires dynamic typing whereas the classical based approach does not===&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Refactorings don't work the same way===&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
===Static typing assurances===&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72267</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72267"/>
		<updated>2013-02-09T03:27:11Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
&lt;br /&gt;
===Object Creation===&lt;br /&gt;
While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance requires dynamic typing whereas the classical based approach does not'''&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Refactorings don't work the same way'''&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
*'''Static typing assurances'''&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72265</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72265"/>
		<updated>2013-02-09T03:22:42Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
===Object Creation===:While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance requires dynamic typing whereas the classical based approach does not'''&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Refactorings don't work the same way'''&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
*'''Static typing assurances'''&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72264</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72264"/>
		<updated>2013-02-09T03:22:25Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*===Object Creation===:While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance requires dynamic typing whereas the classical based approach does not'''&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Refactorings don't work the same way'''&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
*'''Static typing assurances'''&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72263</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72263"/>
		<updated>2013-02-09T03:20:42Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*====Object Creation====:While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance requires dynamic typing whereas the classical based approach does not'''&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Refactorings don't work the same way'''&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
*'''Static typing assurances'''&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72261</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72261"/>
		<updated>2013-02-09T03:18:49Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Inheritance ==&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Means of achieving inheritance ==&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance requires dynamic typing whereas the classical based approach does not'''&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Refactorings don't work the same way'''&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
*'''Static typing assurances'''&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72260</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72260"/>
		<updated>2013-02-09T03:17:02Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of common names for a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance requires dynamic typing whereas the classical based approach does not'''&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Refactorings don't work the same way'''&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
*'''Static typing assurances'''&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Which is the better approach==&lt;br /&gt;
The classical based method is more traditional and purist compared to the prototype based approach.&lt;br /&gt;
People used to a conventional OOP style may easily get confused. &amp;quot;What do you mean there's only one class called &amp;quot;Thing&amp;quot;?!?&amp;quot; - &amp;quot;How do I extend this final Thing class!?!&amp;quot; - &amp;quot;You are violating OOP principles!!!&amp;quot; - &amp;quot;It's wrong to have all these static functions that act on any kind of object!?!?&amp;quot;&lt;br /&gt;
It is really the type of software, objects that are interacting with each other and functionality that determine which approach needs to be used. &lt;br /&gt;
For instance, if the above soldier example were about an army rather than individual or special divisions in the army then the classical approach would have been more appropriate, as there is already a natural existing hierarchy within the army that can be exploited. It would seem vague if different ranks such as lieutenant, corporal, major, general, etc were to be created as objects rather than classes. Also since each of these ranks can have multiple instances of real world objects associated with them, performing almost exactly the same functions, it would be better to create the ranks as classes and then instantiate each soldier as an object of the respective class.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72256</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72256"/>
		<updated>2013-02-09T02:55:08Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance requires dynamic typing whereas the classical based approach does not'''&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Refactorings don't work the same way'''&lt;br /&gt;
In a prototype based system we are essentially &amp;quot;building&amp;quot; our inheritance heirarchy with code. IDEs / refactoring tools can't really help us since they can't guess our approach. &lt;br /&gt;
Consider the vehicle example. Suppose the Car class had a field &amp;quot;type_of_fuel_used&amp;quot;. This would not be appropriate as every instance of each of its subclass would use a different kind of fuel. Hence it would be better if the field, its setters and getters were moved to the subclass. This would be a push down refactoring which can be achieved by any IDE. Once the push down has occured any object instantiated from one of the 3 classes Bus, Truck or SUV would have its own member variable and the corresponding getter and setter.&lt;br /&gt;
Now consider the soldier example. Suppose some of the objects - the private, airman, green beret and delta are part of the same division sent out on the same mission. Thought the mission is the same, each of them would have a different objective. Thus if objective was a field member of the private object, it would have to be pushed down to all who have cloned from it. This however the IDE would not be able to do as cloning occurs at runtime and there is no way to keep track of all the cloned objects to which the member has to be pushed.&lt;br /&gt;
&lt;br /&gt;
*'''Static typing assurances'''&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72251</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72251"/>
		<updated>2013-02-09T02:32:34Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance requires dynamic typing whereas the classical based approach does not'''&lt;br /&gt;
Since objects are being inherited rather than classes, it is necessary that the language support dynamic typing, otherwise there is no way to determine whether the object that is inheriting from another is eligible to possess certain properties.This in turn means increased overhead, as each time an object's functionality is executed, it must be ensured that the object is of a type that has the required functionality.&lt;br /&gt;
&lt;br /&gt;
In the above example, a green beret has been cloned from a private(army). However, if at runtime the green beret is cloned from an airman basic, then all its properties need to reflect those of the new parent. If the language was static then this would simply throw a compiler error (unless it supported runtime polymorhism).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Static typing assurances'''&lt;br /&gt;
The classical approach offers static typing wherein the type of an object is determined at compile time. Since all languages that allow prototype based inheritance are dynamically typed, it implies more test cases need to be tested to ensure correct behavior for the latter approach.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72240</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72240"/>
		<updated>2013-02-09T01:57:56Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Prototype based inheritance is more suited for a &amp;quot;functional&amp;quot; style of programming'''&lt;br /&gt;
In case of prototype-inheritance we write lots of functions that analyse objects and act appropriately, rather than embedded logic in methods attached to specific classes.&lt;br /&gt;
Consider the case where a private in the army may be trained with handling an anti-tank weapon or may be trained for handling artillery. &lt;br /&gt;
This would be impossible in the class based approach since a private would be a class and only those properties which are generic can be embedded in the private's class logic. However in case of the prototype approach, we already know the object so we define the appropriate function for the object. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72222</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72222"/>
		<updated>2013-02-09T01:22:13Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information on extending the functionality of an object'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Instances can become templates for other instances in case of Protoype-based Inheritance, not so in class-based'''&lt;br /&gt;
if you want to &amp;quot;clone&amp;quot; an object it is easy, just use the existing object as the prototype for the new object. No need to write lots of complex cloning logic for different classes.&lt;br /&gt;
For example, suppose a new program is being introduced to train a junior delta soldier in jungle warfare (say deltaJ), then we simply create a new deltaJ object by cloning an existing delta soldier(using it as a template) in case of Prototype-based inheritance. However in a class based approach, we would have to first create a new subclass deltaJ, instantiate an object of the new class and then write the code to clone the existing  delta soldier.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;br /&gt;
 [http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop http://programmers.stackexchange.com/questions/110936/what-are-the-advantages-of-prototype-based-oop-over-class-based-oop]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72211</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72211"/>
		<updated>2013-02-09T00:16:53Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
*'''Transfer of state information'''&lt;br /&gt;
&lt;br /&gt;
Using prototype-based programming, we are able to treat any object as a prototype and therefore we can extend the object without having to create a new object. In class-based programming, we are committed to the functionality provided by the object at instantiation. If we later need to extend the functionality of the class-based object, we must instantiate a new class-based object that has the desired functionality and transfer state between the two objects.&lt;br /&gt;
&lt;br /&gt;
Consider the transfer of a private from marine corps to green berets. In the prototype-based solution, we simply extend the marine corps object to have the functionality of a Green Beret. In a class-based solution, we must instantiate a new Green Beret object and transfer state from the existing marine corp object to the new Green Beret object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72207</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72207"/>
		<updated>2013-02-09T00:01:03Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 class medium Truck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
 class Soldier&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
 Private = Soldier.new()&lt;br /&gt;
 GreenBeret.prototype = Private&lt;br /&gt;
 GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
 GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72206</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72206"/>
		<updated>2013-02-08T23:59:55Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
 Classical inheritance example&lt;br /&gt;
 class Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class Car inherits Land Vehicle&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 class trucks inherits inherits Car&lt;br /&gt;
 {&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 class mediumTruck inherits Truck&lt;br /&gt;
 {&lt;br /&gt;
 //properties&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
class Soldier&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Private = Soldier.new()&lt;br /&gt;
GreenBeret.prototype = Private&lt;br /&gt;
&lt;br /&gt;
GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr http://wiki.expertiza.ncsu.edu/index.php/CSC/ECE_517_Summer_2008/wiki1_8_smr]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72203</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72203"/>
		<updated>2013-02-08T23:51:06Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
Classical inheritance example&lt;br /&gt;
class Vehicle&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car inherits Land Vehicle&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class trucks inherits inherits Car&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class mediumTruck inherits Truck&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
class Soldier&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Private = Soldier.new()&lt;br /&gt;
GreenBeret.prototype = Private&lt;br /&gt;
&lt;br /&gt;
GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72202</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72202"/>
		<updated>2013-02-08T23:49:04Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
Classical inheritance example&lt;br /&gt;
class Vehicle&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car inherits Land Vehicle&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class trucks inherits inherits Car&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class mediumTruck inherits Truck&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
class Soldier&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Private = Soldier.new()&lt;br /&gt;
GreenBeret.prototype = Private&lt;br /&gt;
&lt;br /&gt;
GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Elimination of meta-regress'''&lt;br /&gt;
&lt;br /&gt;
 No object in a class-based system can be self-sufficient; another object (its class) is needed to express its structure and behavior. On the other hand, in prototype-based systems an object can include its own behavior; no other object is needed to breathe life into it. Prototypes eliminate meta-regress.&lt;br /&gt;
&lt;br /&gt;
For example in case of the soldier, a Delta force unit is its own object. It does not require a an airman basic object to define any of its properties even though it inherits from the same.&lt;br /&gt;
However in case of the vehicle example, a medium truck cannot be an object of its own completely. It would need some of its properties to be defined by its superclass 'vehicle'. Consider the move(direction, speed) function defined for the Vehicle class. In most of the cases the medium truck would inherit this functionality completely. It is not likely to have its own move() function.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72195</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72195"/>
		<updated>2013-02-08T23:22:25Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
''(For the sake of an example, do not assume any of the military categories mentioned to be a class. They are all objects. For example we will not create an object for Green Berets. Rather Green Berets is itself an object. This has been done to avoid the use of naming a soldier and then assigning his type to be a private or a green beret or a navy seal, etc)&lt;br /&gt;
''&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
*'''Object Creation''' :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
Classical inheritance example&lt;br /&gt;
class Vehicle&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car inherits Land Vehicle&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class trucks inherits inherits Car&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class mediumTruck inherits Truck&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
class Soldier&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Private = Soldier.new()&lt;br /&gt;
GreenBeret.prototype = Private&lt;br /&gt;
&lt;br /&gt;
GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Using Preexisting modules'''&lt;br /&gt;
&lt;br /&gt;
Prototypes are more concrete than classes because they are examples of objects rather than descriptions of format and initialization. These examples may help users to reuse modules by making them easier to understand. A prototype-based system allows the user to examine a typical representative rather than requiring him to make sense out of its description&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*'''Support for one-of-a-kind objects''' &lt;br /&gt;
&lt;br /&gt;
Ruby provides a framework that can easily include one-of-a-kind objects with their own behavior. Since each object has named slots, and slots can hold state or behavior, any object can have unique slots or behavior. Class-based systems are designed for situations where there are many objects with the same behavior. There is no linguistic support for an object to possess its own unique behavior, and it is awkward to create a class that is guaranteed to have only one instance. Ruby suffers from neither of these disadvantages. Any object can be customized with its own behavior. A unique object can hold the unique behavior, and a separate &amp;quot;instance&amp;quot; is not needed.&lt;br /&gt;
In the above soldier example, navy seals may be trained in marine combat techniques which makes the navy seal object have its own unique behavior. Similarly a private in the army may be trained to handle tanks, (if he were to be in the cavalry division) which makes it unique for the private(army) object. In a class based approach,if private(marine corps) were to be inherited from private(army) and navy seals inherit from private(marine corps) then it would mean that the navy seal would be trained in tanks too, which is not the case here. However in prototype based inheritance training in tanks can remain unique to the marine corps if it is do desired.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72190</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72190"/>
		<updated>2013-02-08T22:09:59Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Index&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
Object Creation :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
Classical inheritance example&lt;br /&gt;
class Vehicle&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car inherits Land Vehicle&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class trucks inherits inherits Car&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class mediumTruck inherits Truck&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance example&lt;br /&gt;
&lt;br /&gt;
class Soldier&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Private = Soldier.new()&lt;br /&gt;
GreenBeret.prototype = Private&lt;br /&gt;
&lt;br /&gt;
GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72188</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72188"/>
		<updated>2013-02-08T22:08:56Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Index&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
Object Creation :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
Classical inheritance&lt;br /&gt;
class Vehicle&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car inherits Land Vehicle&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class trucks inherits inherits Car&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class mediumTruck inherits Truck&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prototype based inheritance&lt;br /&gt;
class Soldier&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Private = Soldier.new()&lt;br /&gt;
GreenBeret.prototype = Private&lt;br /&gt;
GreenBeret.weapon=(&amp;quot;H&amp;amp;K&amp;quot;)&lt;br /&gt;
GreenBeret.training=(&amp;quot;x months&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72185</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72185"/>
		<updated>2013-02-08T21:59:22Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Index&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
Object Creation :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
class Vehicle&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car inherits Land Vehicle&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class trucks inherits inherits Car&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
class mediumTruck inherits Truck&lt;br /&gt;
{&lt;br /&gt;
//properties&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72173</id>
		<title>CSC/ECE 517 Spring 2013/ch1a 1e pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2013/ch1a_1e_pi&amp;diff=72173"/>
		<updated>2013-02-08T20:57:41Z</updated>

		<summary type="html">&lt;p&gt;Ashray: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== Inheritance ===&lt;br /&gt;
In [http://en.wikipedia.org/wiki/Object-oriented_programming object-oriented programming] (OOP), inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Index&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Means of achieving inheritance ===&lt;br /&gt;
'''Classical Inheritance'''&lt;br /&gt;
Objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, or parent classes. The resulting classes are known as derived classes, subclasses, or child classes. The relationships of classes through inheritance gives rise to a hierarchy. &lt;br /&gt;
&lt;br /&gt;
[[File:Inheritance(Classical Inheritance).png| center]]&lt;br /&gt;
&lt;br /&gt;
'''Prototype Based Inheritance'''&lt;br /&gt;
A feature of object-oriented programming  in which classes  are not present and inheritance is  performed via a process of [http://en.wikipedia.org/wiki/Cloning_(programming) cloning] existing objects that serve as [http://en.wikipedia.org/wiki/Prototype prototypes] .   [http://en.wikipedia.org/wiki/Delegation_(programming) Delegation] is the language feature that supports prototype-based programming.&lt;br /&gt;
&lt;br /&gt;
A simple example of Prototype Based Inheritance could be depicted as &lt;br /&gt;
&lt;br /&gt;
[[File:Priority Inheritnce Fig2.jpg|300px|center]].  &lt;br /&gt;
&lt;br /&gt;
This example shows soldiers belonging to different divisions as different objects. This sort of a relation can be better be represented as a prototype based inheritance than as a class-based one. If the relation used was the classical approach, then a separate class &amp;quot;soldier&amp;quot; would have to be defined as  the base class from which the rest of the classes such as delta, green berets and navy seals would have to be defined as children classes. Also these would have been the children classes from which the object itself(probably a real soldier) would have to be instantiated. There is no reason to do so in this case as, each of these, intuitively suit more as an object(real life) than as a passive conceptual class. Besides, the classical approach would bring about a hierarchy among the objects when none exists.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Classical Inheritance v/s Prototype based inheritance==&lt;br /&gt;
Object Creation :While in the case of the classical approach, objects need to be instantiated after defining the format of the class, in case of prototype based, a new object can be instantiated by simply creating a copy of/cloning an existing object. As in &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Prototype-based_programming  http://en.wikipedia.org/wiki/Prototype-based_programming]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Delegation_(programming) http://en.wikipedia.org/wiki/Delegation_(programming)]&lt;br /&gt;
&lt;br /&gt;
 [http://en.wikipedia.org/wiki/Cloning_(programming) http://en.wikipedia.org/wiki/Cloning_(programming)]&lt;/div&gt;</summary>
		<author><name>Ashray</name></author>
	</entry>
</feed>