Skip to content

Instantly share code, notes, and snippets.

@ShirakawaYoshimaru
Last active June 11, 2016 00:35
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/9e8d803cbfff8e1a1fd4dfc14d91bced to your computer and use it in GitHub Desktop.
Save ShirakawaYoshimaru/9e8d803cbfff8e1a1fd4dfc14d91bced 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 ();
}
}
//機能クラス
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