public interface IPostResponser
{
void PostProcess(NetMessageResponse message);
}
class NetSession : INetSession
{
public IPostResponser PostResponser { get; set; }
...
public void Disconnected()
{
this.PostResponser = null;
}
public byte[] GetResponse()
{
if (PostResponser != null)
this.PostResponser.PostProcess(Response);
......
}
}
請問
1. 這種介面的用法叫什么?
2. this.PostResponser是不是在NetSession構造的時候就為非空了?
謝謝各位大佬
uj5u.com熱心網友回復:
1、表示PostResponser是實作了該介面的型別2、要看NetSession的建構式怎么寫了,如果有建立該物件的代碼,就不是null了
uj5u.com熱心網友回復:
1等效于
public class C_PostResponser:IPostResponser
{ }
class NetSession : INetSession
{
public C_PostResponser PostResponser { get; set; }
....................
uj5u.com熱心網友回復:
1. 這種介面的用法叫什么?或許你可以叫它處理機注入模式。如果設定了PostResponser,那么就用它來處理應答資料。
2. this.PostResponser是不是在NetSession構造的時候就為非空了?
NetSession構造的時,為空。構造后,可以后續設定。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/73244.html
標籤:C#
上一篇:gRPC搭建使用方式
