IBM
Contents Index Previous Next



Combining the Properties of Two Process Types


What You Will Learn

So far, you have created a basic version of the game (the supertype process type Game), and extended it as two subtypes (the process types JackpotGame and -DoubleGame). To assist you in understanding the inheritance and instantiation of types, the SDL Suite is provided with a "class browser", the Type Viewer.

Working with the Type Viewer

  1. Open the Type Viewer with the command Type Viewer from the Organizer's Tools > SDL menu.
    The Type Viewer is started and displays two windows: the main window, where all types are listed, and the Type Trees, where the inheritance and instantiation of the types is visualized.

Figure 164 : The two windows of the Type Viewer

The main window displays a list of all types and instances that exist in your current system. When selecting an object in the main window, the Type Trees window is updated to show the inheritance tree for that type.

Figure 165 : The inheritance tree for the process type Game

Figure 165 shows an inheritance tree for the process types Game, -JackpotGame and DoubleGame. We have one level of inheritance, as depicted above. You can also note that the Type Viewer keeps track about the types that have been instantiated somewhere in the SDL system.

How to Work-Around the Lack for Multiple Inheritance

Say that you would like to design a new game where both the "jackpot" and the "double" features are supported. As SDL-92 does not support multiple inheritance, we cannot simply create a SuperGame that inherits JackpotGame and DoubleGame. Instead, we will have to inherit from, i.e. reuse, the JackpotGame or the DoubleGame, and then redefine/add some of the properties. (The idea is to rewrite as little code as possible).

Which one should we reuse as is? The code for the DoubleGame seems to be still valid for the SuperGame. So, let us inherit that process type, and redefine some of the properties in accordance to the JackpotGame.

To create the SuperGame:

  1. Open the process type JackpotGame in the SDL Editor, and Save As on a new file, e.g. -new_supergame.spt
    • This diagram is also available as the file supergame.spt, if you wish to make a copy (or use it as is) instead of drawing the diagram. In that case, continue with step 6. below.
  2. Rename the diagram to process type SuperGame.
  3. Change the inheritance from "INHERITS Game" to "INHERITS -DoubleGame".
  4. Update the contents of the graph, in order to:
    • Change the branch Winning/Probe so that you add Stake instead of 1 to Count when winning, and reward you with 10 times the value of Stake when winning the jackpot.
    • Redefine the transition Losing/Probe so that you deduct Stake instead of 1 from Count.

Figure 166 : The changes to the process type SuperGame

  1. If the Process Type JackpotGame has become unconnected in the Organizer, re-connect it to the file used earlier (new_jackpotgame.spt).
  2. Also add a process type reference symbol with the name -SuperGame in the diagram GameBlock. In the Organizer, then connect the newly added process type diagram SuperGame to the file new_supergame.spt that you created earlier.
  3. You may check the impact of the changes above in the Type Viewer. Save everything and the select Update from the Type Viewer's File menu (since the Type Viewer does not automatically update its content when you make changes to a diagram). Your inheritance tree should now look like this:

Figure 167 : The process type SuperGame, added

  1. If you want to be able to play the SuperGame, you must also add a process instantiation symbol "SuperGame(0,1):SuperGame" in the GameBlock, and add a signal NewSuperGame that starts the game (in a similar fashion as you did in the JackpotGame and the DoubleGame). Do not forget to update the system diagram.
    • These versions of the diagrams are also available as the files gameblock.sbk and demongame.ssy, if you wish use them instead of editing the diagrams. In the Organizer, connect the diagrams to the new files. A complete and final system file, demongame_sdl92.sdt, is also available, with connections to the final SDL diagrams.

http://www.ibm.com/rational
Contents Index Previous Next