(1)在一个类中编写普通的virtual方法
(2)在派生类中实现接口中的方法时,也可以标记为virtual
public interface IServer { /// <summary> /// 响应GET方法 /// </summary> /// <param name="request">Http请求</param> void OnGet(HttpRequest request, HttpResponse response); /// <summary> /// 响应Post方法 /// </summary> /// <param name="request">Http请求</param> void OnPost(HttpRequest request, HttpResponse response); /// <summary> /// 响应默认请求 /// </summary> /// <param name="request">Http请求</param> void OnDefault(HttpRequest request, HttpResponse response); }
public class HttpServer : IServer
{
/// <summary> /// 响应Post请求(virtual作用:在子类中可以被重写,从而提现个性化;在此处编写公共逻辑,从而体现共性) /// </summary> /// <param name="request"></param> public virtual void OnPost(HttpRequest request, HttpResponse response) {
}
}
|
请发表评论