static void Main(string[] args) { //LAB#2 //Dependency Injection IOutput Output; Output = new ConsoleOutput(); //Instantiate Factories var batteryFactory = new BatteryFactory(Output); var chargerFactory = new ChargerFactory(Output); var screenFactory = new ScreenFactory(Output); var playbackFactory = new PlaybackFactory(Output); MobilePhone simCorpMobile = SimCorpMobile.Instance; int Index; #region BatteryComponent //Ask User for an index Index = batteryFactory.SelectComponentIndex(); //Create Component Class based on index simCorpMobile.Battery = batteryFactory.Create(Index).MobileComponent as IBattery; //Do something simCorpMobile.Install(); #endregion #region ChargerComponent //Ask User for an index Index = chargerFactory.SelectComponentIndex(); //Create Component Class based on index simCorpMobile.Charger = chargerFactory.Create(Index).MobileComponent as ICharger; //Do something simCorpMobile.Charge(); #endregion #region ScreenComponent //Ask User for an index Index = screenFactory.SelectComponentIndex(); //Create Component Class based on index simCorpMobile.DisplayScreen = screenFactory.Create(Index).MobileComponent as IScreen; simCorpMobile.Show(); simCorpMobile.TouchScreen = simCorpMobile.DisplayScreen as IScreenTouch; simCorpMobile.Touch(); #endregion #region PlaybackComponent //Ask User for an index Index = playbackFactory.SelectComponentIndex(); //Create Component Class based on index simCorpMobile.Playback = playbackFactory.Create(Index).MobileComponent as IPlayback; simCorpMobile.Play(); #endregion System.Console.ReadLine(); }
private void button1_Click(object sender, EventArgs e) { //======================================================================================= //Clear textBox tbOutput.Clear(); //return Selected radiobutton index int rbIndex = CheckSelectedRadioButton(WinForm); if (rbIndex != 0) { MobilePhone simCorpMobile = SimCorpMobile.Instance; //create class with DI PlaybackFactory playbackFactory = new PlaybackFactory(WinForm); //create component class simCorpMobile.Playback = playbackFactory.Create(rbIndex).MobileComponent as IPlayback; //show playing device in textbox simCorpMobile.Play(); } //======================================================================================= }