我有表示沿着服务器链消息流的示范方案:如何在NModel中封装状态变量?
public class MyModel
{
static bool x_send_msg1 = false; // has X sent msg1?
static bool y_recv_msg1 = false; // has Y received msg1?
static bool y_send_msg1 = false; // has Y sent msg1?
static bool z_send_msg1 = false; // has Z received msg1?
// (etc for more servers and more messages)
[Action]
static void YSendMsg1()
{
// Y sends Msg1 to Z
y_send_msg1 = true;
z_recv_msg1 = true;
}
static bool YSendMsg1Enabled()
{
// in the simplest case, this can happen whenever Y has received the
// message but not yet forwarded it
return y_recv_msg1 && !y_send_msg1;
}
}
有许多更多的消息。每个服务器和消息类型启用()的逻辑略有不同,但国家是相似的,所以我想通过写更多的东西一样来封装它:
class State
{
public bool send_msg1 = false;
public bool recv_msg1 = false;
}
public static State X = new State();
public static State Y = new State();
,然后使用封装状态我的行动:
[Action]
static void YSendMsg1()
{
// instead of y_qqq above, now we can write Y.qqq:
Y.send_msg1 = true;
Z.recv_msg1 = true;
}
static bool YSendMsg1Enabled()
{
return Y.recv_msg1 && !Y.send_msg1;
}
但是NModel不会让我以这种方式使用对象来保持我的状态。有没有其他一些方法可以避免定义重复的布尔组,为链中的每个服务器定义一组?
如果NModel引擎不让我分析一个简单的类/结构,为什么你认为它会让我分析一个多类模式? – Eric 2009-12-17 14:44:55