Created
June 11, 2016 00:39
-
-
Save ShirakawaYoshimaru/3ae4104e4782a4affe45f0ccd342b1ba 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 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