void Main() { Subject subject = new Subject{ Input = "Hello World" }; (new InterpreterA()).Interprete(subject); subject.Output.Dump(); (new InterpreterB()).Interprete(subject); subject.Output.Dump(); } class Subject{ public string Input { get; set; } public string Output { get; set; } } abstract class Interpreter{ public abstract void Interprete(Subject subject); } class InterpreterA:Interpreter{ public override void Interprete(Subject subject){ subject.Output=subject.Input.ToLower(); } } class InterpreterB:Interpreter{ public override void Interprete(Subject subject){ subject.Output=subject.Input.ToUpper(); } }
时间: 2024-10-11 10:05:04