![]() |
![]() |
![]() |
![]() |
![]() |
Combining the Properties of Two Process Types
What You Will Learn
- To work with the Type Viewer (the "class browser" in the SDL Suite)
- To inherit process types in more than one level
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
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 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.
- 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.
- Rename the diagram to process type SuperGame.
- Change the inheritance from "INHERITS Game" to "INHERITS -DoubleGame".
- Update the contents of the graph, in order to:
- If the Process Type JackpotGame has become unconnected in the Organizer, re-connect it to the file used earlier (new_jackpotgame.spt).
- 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.
- 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:
- 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 |
![]() |
![]() |
![]() |
![]() |