Created
May 9, 2017 14:39
-
-
Save Pregum/c10f39c7c9ea03712132796951217bfd 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
namespace TemplateMethod | |
{ | |
public interface Animal | |
{ | |
string GetVoice(); | |
} | |
public class Dog : Animal | |
{ | |
public string GetVoice() | |
{ | |
return "わん"; | |
} | |
} | |
public class Cat : Animal | |
{ | |
public string GetVoice() | |
{ | |
return "にゃー"; | |
} | |
} | |
} |
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 System; | |
using System.Collections.Generic; | |
namespace TemplateMethod | |
{ | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
//ポリモーフィズムのテストコード | |
var animalList = new List<Animal> | |
{ | |
new Dog(), | |
new Cat(), | |
}; | |
foreach (var animal in animalList) | |
{ | |
Console.WriteLine(animal.GetVoice()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment