Composition over Inheritance
We had often heard that composition is better than inheritance. Why is it so? First of all how is one different from the other and what are the similarities in them? Lets say we are writing simulation software for Rocket Launching systems which are to be supplied to different countries. Now these different countries can use them as they want it. The code for our launching system is below: public class Launcher { public bool LaunchMissile() { Console .WriteLine( "Missile launched" ); return true ; } } public class SufraceToAirMissileLauncher : Launcher { } Now, country A uses this code to launch missile as follows: static void Main( string [] args) { SufraceToAirMissileLauncher staLauncher = new SufraceToAirMissileLauncher (); bool isLaunched = staLauncher.LaunchMissile(); } This is how Inheritance is used. The various launchers can reuse the base Launcher class code to launch m