Last active
June 11, 2016 00:35
-
-
Save ShirakawaYoshimaru/9e8d803cbfff8e1a1fd4dfc14d91bced 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 (); | |
} | |
} | |
//機能クラス | |
public class Human | |
{ | |
protected Speak speak; | |
public Human (Speak speak) | |
{ | |
this.speak = speak; | |
} | |
public void Hellow () | |
{ | |
this.speak.SayHellow (); | |
} | |
} | |
//機能クラス | |
public class God : Human | |
{ | |
public God (Speak 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 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