(使用 C# 在 .net 环境中工作)
我们正在编写一个专用服务器,它管理多个数据提供代理,这里有一些伪代码,以便简化解释:
class Server
{
ServerManagementGUI server_gui; // a GUI to display all sort of Server related data
MonitorAgent m_agnt;
DataAgent d_agnt;
// will not be allocated or init at C'tor
public write_data1();
public write_data2();
public get_data5();
// etc
}
class Agent
{
// handles generic communication and threading issues
// a reference to Server is required to write
// the data to it's private data structures.
// please note that a delegate to one or more function will not suffice here.
Agent(Server server);
}
class MonitorAgent : Agent
{
// handles task spesific issues
}
class DataAgent : Agent
{
// handles task spesific issues
}
这个想法是代理异步收集数据,并处理任何通信和线程问题,并使用Server
's 方法填充它的数据结构。我们不确定以上是否是“良好实践”设计。
如果您对我们的设计有任何其他想法或见解,请告诉我们。
更新:
Server
还有一个 GUI 对象,它拥有一些信息。因为代理是那些实际生成数据的人(从网络获取数据,或从硬件传感器获取数据),所以它必须能够直接访问ServerManagementGUI
. 现在,由于每个代理使用不同的方法和 and 属性Server
,ServerManagementGUI
我们认为只传递对整个对象的引用是最方便的。