Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
DI
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public interface IEngine { void Run(); } public class CarEngine : IEngine { public void Run() { Console.WriteLine("Car engine is running successfully"); } } public class BikeEngine : IEngine { public void Run() { Console.WriteLine("Bike engine is running successfully"); } } public class LorryEngine : IEngine { public void Run() { Console.WriteLine("Lorry engine is running successfully"); } } public class ExecuteEngine { private readonly IEngine _engine; public ExecuteEngine(IEngine engine) { _engine = engine; } public void RunEngineMethod() { _engine.Run(); } } public static void Main(string[] args) { //At run time with the help of dependency injection, we can insert any kind of object that is inhering from the same interface and can achive, //1. Loose coupling //2. Open closed rule by extending the method "Run() in different classes 'CarEngine', 'BikeEngine', 'LorryEngine'". //3. Testability by replacing different objects in the ExecuteEngine method. ExecuteEngine carEngine = new ExecuteEngine(new CarEngine()); ExecuteEngine bikeEngine = new ExecuteEngine(new BikeEngine()); ExecuteEngine lorryEngine = new ExecuteEngine(new LorryEngine()); carEngine.RunEngineMethod(); bikeEngine.RunEngineMethod(); lorryEngine.RunEngineMethod(); } } }
run
|
edit
|
history
|
help
0
Nice Stuff
Informashin prsonely
Numeric to graphical styling using String Extension method
s 3
interface
seconds to minutes, hour and seconds
Bubble Sort
NationalCode
Sum of 3
Fibonacci with Given Length