English 中文(简体)
C# - 《通过参考书》时的设计图
原标题:C# - Design Thoughts on Passing by Reference

我有一个C#Windows Service, 即通过电子邮件和贴切评论的路线,以备<代码>Agents(实际上我不喜欢——但该信的内容非常相似)。 因此,我有一份<代码>的代理人清单,以及将这些电子邮件和信条送交现有代理人的逻辑。

我的法典如何看待?

I have an AgentManager class that keeps track of which agents are available, their skill levels, etc. I have an EmailManager class that routes Emails to Agents. I have a TwitterManager class that routes Tweets to Agents.

因此,与<代码>Agents有关的逻辑,例如<代码>Agents,该编码具备<代码>Tweet 的能力,该编码具有<编码>Email的能力,等等,均载于<代码>AgentManager。

现在,当<代码>EmailManager>发现有新的电子邮件,需要将其指定到Agent时,我希望

查阅我从<代码>Agentager上的代理人名单(不回到数据库,也不在<编码>EmailManager上保留代理人名单)。

我的初步想法是通过<代码>AgentManager至 EmailManager。 我之所以要这样做,是因为代理人改变状态,增加/移走等—— 电子邮箱:Manager将永远是工作证人

h 最新<代码>AgentManager(并因此成为最新动态清单)。 有些人认为,这是 d。 我知道,这样做是徒劳的,但看来是处理这一问题的好办法。 我这样做是错误的吗?

EDIT: I am passing the AgentManager by reference for storage, not to change it in the EmailManager class.

最佳回答

From your descriptions seems more soud to go the other way.
An AgentManager process EMails and Tweets and knows everything of its Agents -
So it should have a method that receive a list of EMails/Tweets and process them.

由于我们谈论的是参考型号,所以关于通过反省的问题不明确。

For example:

AgentManager ag = new AgentManager();
EMailManager eg = new EMailManager();
TweetManaget tg = new TweetManager();

eg.LoadEMail();
List<EMails> mails = eg.GetMailsList();

tg.LoadTweet();
List<Tweets> tws = tg.GetTweetsList();

ag.ProcessData(mails, tws);

EDIT: Looking at the comment from OP I have thought of another strategy
Let the EMailManager and TweetManager declare an Event to which the AgentManager subscribe-

eg.EmailReceived += ag.NotifyEmail;
tg.TweetPolled += ag.NotifyTweet;


public class EventManager
{
    public delegate void OnMailReceived(EMails m);
    public event MailReceived;

    ........

    private void GetMail()
    {
        EMails m;
        .....
        if(MailReceived != null) 
            MailReceived(m);
    }
}

public class AgentManager()
{
     public void NotifyEMail(EMails m)
     {
         .....
     }


}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签