PDA

View Full Version : Polimorphism


frcol
10-29-2009, 11:08 AM
Iīve already read somewhere that Alice not supports polimorphism.

So, I canīt make a LIST of Objects, put "persons" inside this List and call the List[1].Say() method, correct?

or is there another way?

x2495iiii
10-29-2009, 09:16 PM
Wait, do you want all of the objects in the list to say something at the same time, or do you want each object to say something unique to the object, but still from inside a list?

frcol
10-30-2009, 12:36 AM
Wait, do you want all of the objects in the list to say something at the same time, or do you want each object to say something unique to the object, but still from inside a list?

Each object to say something unique.
For example, when we pass the "whatWasPicked()" as parameter to the method, it would be great if we could call a method from it.

test(whatWasPicked());

public void test(Object myObj)
{
myObj.Say(myObj.text); // text is an object property
}

for each object that I clicked, it would say a unique message.

xxledzeppelin2x3
10-30-2009, 09:16 PM
i dont think you can do that but dont fully take my work i would rely on x2495iiii's input!

x2495iiii
10-31-2009, 12:59 AM
Here's my input:
You can do that by creating a 3d text for each object (or possibly even just a cone or dummy object for each object, either will work, really) which has the text you want the corresponding object to say for a name. Then, give all of the possible objects an object variable called speech (make sure ALL of them are called speech, same spelling, same casing) which is set to the corresponding object (Say you want a cat to say meow when it is clicked. You create an object named meow, then give the cat an object variable and set it's value to the meow object). Now, when the object is passed as a parameter, have the parameter say something, then drag the "[what] as string" function onto the text it's supposed to say, then drag the cat's function (located way at the bottom) ""[cat's] variable of type [type] called [variable]" onto the [what] part of the what as string function. Finally, drag the parameter's name over the cat's name change the name of the variable to speech, and change the type to object.

I did write a demo, as this gets somewhat complex. The only flaw is that if you click the sky, an error generates. This can be fixed, though, by making a list of objects which can be clicked on and testing to see if the object clicked on equals at least one of those object (you still don't need to know which one).

xxledzeppelin2x3
10-31-2009, 10:22 AM
once again i was proved wrong by a 5 paragraph essay and demo by x2495iiii, :p