-
03/17 인터페이스연습 2C#/수업내용 2021. 3. 17. 13:03
Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { class Program { static void Main(string[] args) { Console.WriteLine("Main"); new App(); } } }
App.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class App { public App() { Observer observer = new Observer(); observer.DoTransparent(); observer.Fly(); observer.Move(); DarkTemplar darkTemplar = new DarkTemplar(); darkTemplar.DoTransparent(); darkTemplar.Move(); Zealot zealot = new Zealot(); zealot.Move(); } } }
ProtossUnit.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class ProtossUnit { public ProtossUnit() { Console.WriteLine("{0}가 생성되었습니다.", this.GetType().Name); } public virtual void Move() { Console.WriteLine("가 이동합니다."); } } }
ITransparent.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { interface ITransparent { void DoTransparent(); } }
IFly.csusing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { interface IFly { void Fly(); } }
Observer.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class Observer : ProtossUnit, IFly, ITransparent { public Observer() { } public void DoTransparent() { Console.WriteLine("{0}가 투명화했습니다.", this.GetType().Name); } public void Fly() { Console.WriteLine("{0}가 비행합니다.", this.GetType().Name); } public override void Move() { Console.Write(this.GetType().Name); base.Move(); } } }
DarkTemplar.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class DarkTemplar : ProtossUnit, ITransparent { public DarkTemplar() { } public void DoTransparent() { Console.WriteLine("{0}가 투명화했습니다.", this.GetType().Name); } public override void Move() { Console.Write(this.GetType().Name); base.Move(); } } }
Zealot.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class Zealot : ProtossUnit { public Zealot() { } public override void Move() { Console.Write(this.GetType().Name); base.Move(); } } }
'C# > 수업내용' 카테고리의 다른 글
03/17 stack 연습 (0) 2021.03.17 03/17 abtract 연습 (0) 2021.03.17 03/17 인터페이스 연습 1 (0) 2021.03.17 03/17 List<T> 변수 선언, 인스턴스 생성, 값 할당, 출력 복습 2 (0) 2021.03.17 03/17 배열 변수 선언, 인스턴스 생성, 값 할당, 출력 복습 2 (0) 2021.03.17