Inheriting Classes

Updated on November 8, 2018 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on November 8, 2018

I am currently following the Tower Defense Tutorial and have a question regarding inheriting.  In the tutorial under the GameMaster GameObject there are quite a few classes.  Most of these use the same GameObjects (ex: SceneFader).  Wouldn’t be better to create a parent class of GameMaster and then inherit for the other classes to the GameMaster?  WaveSpawner : GameMaster.  And then only one reference to the SceneFader would be needed.  

Is there an issue with doing it this way?  

Thank you in advance.

  • Liked by
Reply
0 on November 8, 2018

You don’t really want to inherit like that if the classes aren’t actually extensions of the parent class. There isn’t anything wrong with it, other than just bad practice.

If your goal is to cut down on references or GetObject calls, then try making things like SceneFader a singleton. That way you just have to use it’s static reference and don’t have to worry about getting any null errors.

  • Liked by
Reply
Cancel
0 on November 8, 2018

Thank you for the input.  I see what you are saying.  Have a great day.

  • Liked by
Reply
Cancel