Skip to content

Instantly share code, notes, and snippets.

@ShirakawaYoshimaru
Created June 11, 2016 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShirakawaYoshimaru/3ae4104e4782a4affe45f0ccd342b1ba to your computer and use it in GitHub Desktop.
Save ShirakawaYoshimaru/3ae4104e4782a4affe45f0ccd342b1ba to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using System;
//使い方
public class TestScript : MonoBehaviour
{
void Start ()
{
new Human (new Speak ()).Hellow ();
new God (new Speak ()).Hellow ();
new God (new Speak ()).SuperHellow ();
new Human (new NaturalSpeak ()).Hellow ();
new God (new NaturalSpeak ()).SuperHellow ();
}
}
//機能クラス
public class Human
{
//実装interfaceで受け付けるように修正
protected ISpeak speak;
public Human (ISpeak speak)
{
this.speak = speak;
}
public void Hellow ()
{
this.speak.SayHellow ();
}
}
//機能クラス
public class God : Human
{
public God (ISpeak speak) : base (speak)
{
}
public void SuperHellow ()
{
for (int i = 0; i < 10; i++) {
this.speak.SayHellow ();
}
}
}
//実装interface
public interface ISpeak
{
void SayHellow ();
void SayGoodBay ();
}
//実装クラス
public class NaturalSpeak : ISpeak
{
public void SayHellow ()
{
Debug.Log ("やぅっほぉー!");
}
public void SayGoodBay ()
{
Debug.Log ("じゃあね〜〜〜〜〜!");
}
}
//実装クラス
public class Speak : ISpeak
{
public void SayHellow ()
{
Debug.Log ("やっほー");
}
public void SayGoodBay ()
{
Debug.Log ("じゃあね");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment