Created
September 4, 2018 08:07
-
-
Save sakshamsaxena/a49db028e9f26f25df7e4bdd731abfde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace DemoApp | |
{ | |
public class Almira | |
{ | |
private Door Door { get; set; } | |
public void LockAlmira() | |
{ | |
this.Door.LockDoor(); | |
} | |
public Almira(Door door) | |
{ | |
this.Door = door; | |
} | |
} | |
public class Door | |
{ | |
public void LockDoor() | |
{ | |
// Implementation | |
Console.Write("Locked!"); | |
} | |
public Door() | |
{ | |
// Constructor | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Without Injector (Good way) | |
Almira al = new Almira(new Door()); | |
al.LockAlmira(); | |
// With Injector (Not so good way) | |
Injector ij = new Injector(); // However you create the injector (depends on language) | |
Almira al = ij.getInstance("Almira"); | |
al.door.lockDoor(); // Does what the implementation tells it to | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment