基础参数
interface,abstract,virtual,override
然后实现了这样的效果
同一个方法,调用不同的实现类,那实现不一样的结果
具体代码
public interface IStatsBase{string UserSpeak(string content);string UserHandel(string content);}public interface IUserStatsBase{string UserLook(string content);}public abstract class UserStatsBase : IUserStatsBase, IStatsBase{protected abstract string Name { get; }public virtual string UserHandel(string content){return $"{Name}做:{content}";}public virtual string UserSpeak(string content){return $"{Name}说:{content}";}public virtual string UserLook(string content){return $"{Name}看:{content}";}}public class XiaoHongStats : UserStatsBase{protected override string Name => "小红";public override string UserHandel(string content){StringBuilder str = new StringBuilder();str.AppendLine(UserSpeak("我那去扫地"));str.AppendLine("去扫地了");return str.ToString();}}public class ZhangSangStats : UserStatsBase{protected override string Name => "张三";public override string UserSpeak(string content){return $"{Name}说:{content},并且带着大家去做";}}