Created
August 2, 2018 21:42
-
-
Save Spartee/8fe48f54a32f44f1bceb95a59175a188 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SomeAnimals { | |
class Animal { | |
var animalType: string; | |
} | |
class Bird: Animal { | |
proc init(aType: string) { | |
this.animalType = aType; | |
} | |
proc fly() { | |
writeln("flying.."); | |
} | |
} | |
class Fish: Animal { | |
proc init(aType: string) { | |
this.animalType = aType; | |
} | |
proc swim() { | |
writeln("swimming.."); | |
} | |
} | |
} // module SomeAnimals | |
proc main() { | |
use SomeAnimals; | |
const fish: Animal = new Fish("fishtype"); | |
const bird: Animal = new Bird("birdtype"); | |
const animals = [fish, bird]; | |
for animal in animals { | |
select animal.animalType { | |
when "fishtype" do (animal:Fish).swim(); | |
when "birdtype" do (animal:Bird).fly(); | |
} | |
} | |
} // proc main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment