home *** CD-ROM | disk | FTP | other *** search
- // %PARAMETERS = "CH20LIST C:\UT2004"
- //Identifies the package
- //CH20_08LIST.uc
- //This class provides you with a demonstration of
- //Polymorphism using Prop, SoundProp, and BackProp
-
- class CH20_08LIST extends Commandlet;
- function int Main(string Args)
- {
- //#1
- local SoundProp firstSndProp;
- local StageProp firstStgProp;
- local Array<Prop> rgProps;
-
- firstSndProp = new class'SoundProp';
- firstStgProp = new class'StageProp';
-
- Log(Chr(10)$ " Using polymorphism " $ Chr(10) );
- //#2
- firstSndProp.setName("Sirens.");
- firstSndProp.setAction("Play");
- firstSndProp.setPPos(2);
- firstSndProp.setNumber(222);
-
- firstStgProp.setName("Vista of canyon");
- firstStgProp.setAction("R");
- firstStgProp.setNumber(444);
-
- //#3
- //For the sound
- Log(Chr(10) $ " SoundProp name: " $ firstSndProp.getName());
- Log( " SoundProp number: " $ firstSndProp.getNumber());
- Log( " SoundProp action: " $ firstSndProp.getAction());
-
- //For the back scene
- Log(Chr(10) $ " StageProp name: " $ firstStgProp.getName());
- Log( " StageProp number: " $ firstStgProp.getNumber());
- Log( " StageProp action: " $ firstStgProp.getAction());
-
- //#4
- //Assign the objects to an array of the Prop type
- rgProps[0] = firstSndProp;
- rgProps[1] = firstStgProp;
-
- //Polymorphism used to store both types of object in
- //a Prop array
-
- Log(Chr(10) $ " Polymorphism: Store and retrieve "
- $ "objects using a Prop array");
-
- Log(Chr(10) $ " SoundProp name: " $ rgProps[0].getName());
- Log( " SoundProp number: " $ rgProps[0].getNumber());
- Log( " SoundProp action: " $ firstStgProp.getAction());
-
- //For the back scene
- Log(Chr(10) $ " StageProp name: " $ rgProps[1].getName());
- Log( " StageProp number: " $ rgProps[1].getNumber());
- Log( " StageProp action: " $ rgProps[1].getAction());
-
- //#5
- //Polymorphism used to pass both types of argument
- //to a function defined with the type of the parent class
-
- Log(Chr(10) $ " Pass both objects to a function defined ");
- Log( " with Prop as the argument type");
- Log( " Again, this is Polymorphism");
-
- //The same function accepts the two data types
- showProp(firstSndProp);
- showProp(firstStgProp);
-
- return 0;
- }
-
- //#6
-
- //-----------------------showProp-------------------------------
- public function showProp(Prop locProp){
- Log(Chr(10) $ " " $ locProp.class
- $ ": " $ locProp.getName());
- Log( " " $ locProp.class
- $ ": " $ locProp.getNumber());
- Log( " " $ locProp.class
- $ ": " $ locProp.getAction());
- }
-