CSC 216 F09/Polymorphism: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
(Create a Creature : Using Inheritance and Polymorphism)
Line 1: Line 1:
<poem>
{{Redirect|Java language|the Indonesian spoken language|Javanese language}}
{{distinguish|JavaScript}}
 
{{infobox programming language
| name                  = Java
| logo                  = [[File:Java logo.svg|100px]]
| paradigm              = [[Object-oriented programming|Object-oriented]], [[Structured programming|structured]], [[Imperative programming|imperative]]
| year                  = [[1995]]
| designer              = [[Sun Microsystems]]
| latest_release_version = Java Standard Edition 6 (1.6.0_17)
| latest_release_date    =
| latest_test_version    =
| latest_test_date      =
| turing-complete        = Yes
| typing                = [[Type system|Static, strong, safe]], [[Nominative type system|nominative]], [[Manifest typing|manifest]]
| implementations        = [[:Category:Java virtual machine|Numerous]]
| influenced_by          =  [[Objective-C]],<ref>[[Patrick Naughton]] cites [[Objective-C]] as a strong influence on the design of the Java programming language, stating that notable direct derivatives include Java interfaces (derived from Objective-C's [[Objective-C#Protocols|protocol]]) and primitive wrapper classes. [http://cs.gmu.edu/~sean/stuff/java-objc.html]</ref> [[Ada (programming language)|Ada 83]], [[Object Pascal|Delphi Object Pascal]]<ref>«We looked very carefully at [[Object Pascal|Delphi Object Pascal]] and built a working prototype of bound method references in order to understand their interaction with the Java programming language and its APIs.» <br/>«Our conclusion was that bound method references are unnecessary and detrimental to the language. This decision was made in consultation with Borland International, who had previous experience with bound method references in [[Object Pascal|Delphi Object Pascal]].» [http://java.sun.com/docs/white/delegates.html White Paper.About Microsoft's "Delegates"], java.sun.com</ref>, [[UCSD Pascal]]<ref>{{cite web|url=http://www.fscript.org/prof/javapassport.pdf|quote=The project went ahead under the name "green" and the language was based on an old model of [[UCSD Pascal]], which makes it possible to generate interpretive code|title=History of Java|work=Java Application Servers Report|author=TechMetrix Research|date=1999}}</ref><ref>http://queue.acm.org/detail.cfm?id=1017013</ref> [[C++]], [[C Sharp (programming language)|C#]],<ref>Java 5.0 added several new language features (the [[foreach|enhanced for loop]], [[autoboxing]], [[variadic function|varargs]] and [[Java annotation|annotations]]), after they were introduced in the similar (and competing) [[C Sharp (programming language)|C#]] language [http://www.barrycornelius.com/papers/java5/][http://www.levenez.com/lang/]</ref> [[Eiffel (programming language)|Eiffel]],<ref>{{ cite web | authors = Gosling and McGilton | title = The Java Language Environment | date=  May 1996 | url = http://java.sun.com/docs/white/langenv/Intro.doc1.html#943 }}</ref> [[Smalltalk]], [[Mesa (programming language)|Mesa]],<ref>{{cite web | authors = J. Gosling, B. Joy, G. Steele, G. Brachda | title = The Java Language Specification, 2nd Edition | url= http://java.sun.com/docs/books/jls/second_edition/html/intro.doc.html#237601 }}</ref> [[Modula-3]],<ref>http://www.computerworld.com.au/index.php/id;1422447371;pp;3;fp;4194304;fpid;1</ref> [[Generic Java]]
| influenced            = [[Ada (programming language)|Ada&nbsp;2005]], [[C Sharp (programming language)|C#]], [[Clojure]], [[D (programming language)|D]], [[ECMAScript]], [[Groovy (programming language)|Groovy]], [[J Sharp|J#]], [[PHP]], [[Scala (programming language)|Scala]], [[JavaScript]], [[Python (programming language)|Python]], [[BeanShell]]
| dialects = [[Generic Java]], [[Pizza (programming language)|Pizza]]
| operating_system      = [[Cross-platform|Cross-platform (multi-platform)]]
| license                = [[GNU General Public License]]&nbsp;/ [[Java Community Process]]
| website                = http://java.sun.com
}}
 
===Formatting Resources===
===Formatting Resources===
[http://meta.wikimedia.org/wiki/Help:Wikitext_examples Formatting Help Guide from MetaWiki]
[http://meta.wikimedia.org/wiki/Help:Wikitext_examples Formatting Help Guide from MetaWiki]
Line 36: Line 59:
Example:
Example:


</poem>
<source lang="java5">
<source lang="java5">
abstract public class Animal {
abstract public class Animal {

Revision as of 05:37, 17 November 2009

Template:Redirect Template:Distinguish

Template:Infobox programming language

Formatting Resources

Formatting Help Guide from MetaWiki

Place Title of Exercise Here

Create A Creature

The problem

Students will learn the principles of inheritance and polymorphism.

Participants and props

This game requires a minimum of three people, but is designed to engage an entire class. A driver created in Flash can be used, but is not required.

The script

The class will be divided up into teams (by row, programming partners, etc.). The first team will be the "Artists," the second team will be the "Programmers," and all of the remaining teams will be the "Designers." Turns cycle from Designer -> Programmer -> Artist

For example: If we divided the class into teams by row and there were 5 rows:

  • row 1 - Artists
  • row 2 - Programmers
  • row 3 - Designers
  • row 4 - Designers
  • row 5 - Designers

After the first rotation, the roles would be:

  • row 2 - Artists
  • row 3 - Programmers
  • row 4 - Designers
  • row 5 - Designers
  • row 1 - Designers

The objective is to create the creatures within a new MMO. To begin, an Animal class has to be created, and the methods/variables of an Animal must also be created. This is the job of the entire class. The current Programming team will type/write this code to be displayed as ideas are called out. Example:

abstract public class Animal {
     private boolean living;
     public void eat();
     public Animal() {
          this.living = true;
     }
     public void die() {
          this.living = false;
     }
}

Now we need to make a subclass that extends Animal.

//name the creature
public class ____ extends Animal {  
     //add unique characteristics
     public ____(){ 
          super();
     }
     public eat(){
         //define herbivore, carnivore, omnivore status
     }
     //add other methods : attack, walk, fly, etc.
}

As each method is written, the artist's must draw a creature that implements those methods. For example, if the hear method requires the creature to attack using a unicorn horn, the artists will add a unicorn horn to the creature. The designers call out ideas, critique written code and drawn animals. It is the designer's job to come up with the components of the creature and what it can do. The programmer's must translate this into code.

The roles rotate after a method has been completed. When the creature is complete, the designers decide if a subclass of this class should be written (i.e. boss, weaker version etc.). The class can create as many creatures as desired, but for the sake of time, 2-3 creatures would complete the lesson.