Become a part of the TranceAddict community!Frequently Asked Questions - Please read this if you haven'tSearch the forums
TranceAddict Forums > Main Forums > Chill Out Room > OO - polymorphism - wtf??
Pages (2): [1] 2 »   Last Thread   Next Thread
Share
Author
Thread    Post A Reply
UglyDave
i ran a marathon : )



Registered: Jan 2003
Location: Buncrana, Éire
OO - polymorphism - wtf??

can some one explain what polymorphism is, as i'm having difficulty findin a good example on the net..

a class mate described it to me as being like this:

u have an alien, a lazer, and a ufo.

you tell them all to draw.

alien draws a pic of an alien.
lazer draws a lazer
ufo draws a ufo.

wtf?

please someone explain!

Dave

Old Post May-14-2004 12:16  Ireland
Click Here to See the Profile for UglyDave Click here to Send UglyDave a Private Message Visit UglyDave's homepage! Add UglyDave to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Kamikaze Badger
Suspended User



Registered: Sep 2003
Location: Guttenberg, Iowa, USA

Le Dictionare says:


quote:
pol·y·mor·phism ( P ) Pronunciation Key (pl-môrfzm)
n.

1. Biology. The occurrence of different forms, stages, or types in individual organisms or in organisms of the same species, independent of sexual variations.
2. Chemistry. Crystallization of a compound in at least two distinct forms. Also called pleomorphism.


___________________
Signature Suspended Because It Was Too Big.


No it wasn't...

Old Post May-14-2004 12:18  United States
Click Here to See the Profile for Kamikaze Badger Click here to Send Kamikaze Badger a Private Message Add Kamikaze Badger to your buddy list Report this Post Reply w/Quote Edit/Delete Message
UglyDave
i ran a marathon : )



Registered: Jan 2003
Location: Buncrana, Éire

Le Dictionare is gay

Old Post May-14-2004 12:20  Ireland
Click Here to See the Profile for UglyDave Click here to Send UglyDave a Private Message Visit UglyDave's homepage! Add UglyDave to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Kamikaze Badger
Suspended User



Registered: Sep 2003
Location: Guttenberg, Iowa, USA

Actually, I think the spelling is Dictionaire or something rather close to that. It's Francais.


___________________
Signature Suspended Because It Was Too Big.


No it wasn't...

Old Post May-14-2004 12:23  United States
Click Here to See the Profile for Kamikaze Badger Click here to Send Kamikaze Badger a Private Message Add Kamikaze Badger to your buddy list Report this Post Reply w/Quote Edit/Delete Message
UglyDave
i ran a marathon : )



Registered: Jan 2003
Location: Buncrana, Éire

i used to go to dictionary.com but i realised it's shite.

now:

google!

type:

define: word

sorted!

Old Post May-14-2004 12:26  Ireland
Click Here to See the Profile for UglyDave Click here to Send UglyDave a Private Message Visit UglyDave's homepage! Add UglyDave to your buddy list Report this Post Reply w/Quote Edit/Delete Message
loconet
de la puta madre!



Registered: Jul 2002
Location: San Francisco
Re: OO - polymorphism - wtf??

quote:
Originally posted by UglyDave
can some one explain what polymorphism is, as i'm having difficulty findin a good example on the net..

a class mate described it to me as being like this:

u have an alien, a lazer, and a ufo.

you tell them all to draw.

alien draws a pic of an alien.
lazer draws a lazer
ufo draws a ufo.

wtf?

please someone explain!

Dave


That's actually a pretty good metaphor of what it is , here is a more formal explanation:

quote:

Polymorphism

Polymorphism is the ability of a class and possibly of different classes to have certain behavior identified by a common name but distinguished when invoked.

This is an extremely powerful feature of object-oriented programming. Consider two distinct classes in an inheritance hierarchy. Let us refer to their instances by their common class name and identify distinct behaviors by the same name. For example, let us ask all 'animals' of various species to 'draw' themselves. We use the common name (animal) and the common behavior (draw), but expect each instance to draw a diagram appropriate to its own species. We do not make separate drawing requests for each species. This enables us to introduce more species without introducing any more source code and to simplify our programming considerably.

Polymorphism means existence in many forms. This concept was first associated with programming by Strachey in 1967.


Source: http://cs.senecac.on.ca/~cszalwin/btp200/objec.html


Example from an ex prof of mine..:

code:
/** Explains polymorphism JAC444 Lesson 4 Slide 11 @version 1.0, May 19, 2000 @author Jordan Anastasiade */ import java.util.*; class Shape { Shape(int i) { System.out.println("\nShape constructor called"); } void cleanup() { System.out.println("Shape cleanup \n"); } } class Circle extends Shape { Circle(int i) { super(i); System.out.println("\tDrawing a Circle \n"); } void cleanup() { System.out.println("\tErasing a Circle"); super.cleanup(); } } class Triangle extends Shape { Triangle(int i) { super(i); System.out.println("\tDrawing a Triangle \n"); } void cleanup() { System.out.println("\tErasing a Triangle"); super.cleanup(); } } public class DrawSystem extends Shape { private Circle c; private Triangle t; private Shape[] drawObjs; DrawSystem(int nrObjs) { super(nrObjs); drawObjs = new Shape[nrObjs]; c = new Circle(1); t = new Triangle(1); drawObjs[0] = c; drawObjs[1] = t; System.out.println("DrawSystem constructor finishes.\n\n"); } void cleanup() { System.out.println("\n\nSystem.cleanup() begins"); for(int i = 0; i < drawObjs.length; i++) drawObjs[i].cleanup(); super.cleanup(); } public static void main(String[] args) { DrawSystem x = new DrawSystem(2); //drawing methods x.cleanup(); } }


Notice how the cleanup() is called and thanks to polymorphism, the corresponding cleanup from the derived objects are called.


___________________
[alk]

Old Post May-14-2004 12:48  Peru
Click Here to See the Profile for loconet Click here to Send loconet a Private Message Visit loconet's homepage! Add loconet to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Audio Beverage
Addicted



Registered: Dec 2002
Location: Adelaide
Re: OO - polymorphism - wtf??

quote:
Originally posted by UglyDave
can some one explain what polymorphism is, as i'm having difficulty findin a good example on the net..

a class mate described it to me as being like this:

u have an alien, a lazer, and a ufo.

you tell them all to draw.

alien draws a pic of an alien.
lazer draws a lazer
ufo draws a ufo.

wtf?

please someone explain!

Dave


uuhhmm, not enough detail

Think of it like this:

You have ANIMALS. (class Animal)
You have PETS.
PETS are ANIMALS. (class Pet extends Animal)
You have DOGS.
DOGS are PETS(class Dog extends Pet)
You have a POODLE.
POODLES are DOGS.(class Poodle extends Dog)

Now say we command them all to make a noise.

Animal.makeNoise(); //I don't think an undefined animal would make a noise
Pet.makeNoise(); //And I don't think an undefined pet would make a noise either
Dog.makeNoise(); //It would probably go "WOOF"
Poodle.makeNoise(); //It would probably go "eep!eep!"

See what's happening? A class is inheriting the properties of its super class And then USUALLY overiding them.

The dogs makeNose(); method returns "WOOF" while the poodles makeNoise(); method returns "eep!eep!" The classes have inherited their super classes method (makeNoise) but changed them. That's called polymorphism

Old Post May-14-2004 13:30  Australia
Click Here to See the Profile for Audio Beverage Click here to Send Audio Beverage a Private Message Add Audio Beverage to your buddy list Report this Post Reply w/Quote Edit/Delete Message
UglyDave
i ran a marathon : )



Registered: Jan 2003
Location: Buncrana, Éire

thank you everyone who has contributed to this thread!!!

GelatinPuff, i dunno what kinda crazy poodles you have

Old Post May-14-2004 13:45  Ireland
Click Here to See the Profile for UglyDave Click here to Send UglyDave a Private Message Visit UglyDave's homepage! Add UglyDave to your buddy list Report this Post Reply w/Quote Edit/Delete Message
igottaknow
PerfectTeeth R4 Dinosaurs



Registered: Feb 2001
Location: The Future
Re: OO - polymorphism - wtf??

quote:
Originally posted by UglyDave
can some one explain what polymorphism is, as i'm having difficulty findin a good example on the net..

a class mate described it to me as being like this:

u have an alien, a lazer, and a ufo.
you tell them all to draw.

A better example would be:
A priest, a rabbi, and a nun walk into a bar...


___________________
GIGANTIC CUNT

Old Post May-14-2004 14:00 
Click Here to See the Profile for igottaknow Click here to Send igottaknow a Private Message Add igottaknow to your buddy list Report this Post Reply w/Quote Edit/Delete Message
Audio Beverage
Addicted



Registered: Dec 2002
Location: Adelaide

Well that was the only noise I could think of

Plus I guess you're taking programming huh?

You're in for some hard times you know that don't you?

Old Post May-14-2004 14:06  Australia
Click Here to See the Profile for Audio Beverage Click here to Send Audio Beverage a Private Message Add Audio Beverage to your buddy list Report this Post Reply w/Quote Edit/Delete Message
UglyDave
i ran a marathon : )



Registered: Jan 2003
Location: Buncrana, Éire

quote:
Originally posted by GelatinPufF
Well that was the only noise I could think of

Plus I guess you're taking programming huh?

You're in for some hard times you know that don't you?


..now that you're here... what's an abstract method?

Old Post May-14-2004 14:15  Ireland
Click Here to See the Profile for UglyDave Click here to Send UglyDave a Private Message Visit UglyDave's homepage! Add UglyDave to your buddy list Report this Post Reply w/Quote Edit/Delete Message
igottaknow
PerfectTeeth R4 Dinosaurs



Registered: Feb 2001
Location: The Future

what's inheritance? and give an example

can you write me a program that does a bubble sort?


___________________
GIGANTIC CUNT

Old Post May-14-2004 14:22 
Click Here to See the Profile for igottaknow Click here to Send igottaknow a Private Message Add igottaknow to your buddy list Report this Post Reply w/Quote Edit/Delete Message

TranceAddict Forums > Main Forums > Chill Out Room > OO - polymorphism - wtf??
Post New Thread    Post A Reply

Pages (2): [1] 2 »  
Last Thread   Next Thread
Click here to listen to the sample!Pause playbacktechno ownage [2002] [0]

Click here to listen to the sample!Pause playbackBlank & Jones - "Suburban Hell" [2002]

Show Printable Version | Subscribe to this Thread
Forum Jump:

All times are GMT. The time now is 18:12.

Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
HTML code is ON
vB code is ON
[IMG] code is ON
 
Search this Thread:

 
Contact Us - return to tranceaddict

Powered by: Trance Music & vBulletin Forums
Copyright ©2000-2026, Jelsoft Enterprises Ltd.
Privacy Statement / DMCA
Support TA!