C#/수업내용

03/17 인터페이스연습 2

박준희 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.cs

using 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();
        }
    }
}