C# - 基本类设计问题
我正在编写一个应用程序,
该应用程序的主要目的是能够使用 Gmail 帐户快速发送电子邮件(不是阅读电子邮件,只是发送)。
我有一个“GmailAccount”类,它使用用户的用户名和密码在其构造函数中创建一个 SmtpClient 对象。它还有一个“发送”方法,该方法接受将由我的 UI 构建并传递的 MailMessage。
我遇到的问题是,我很想轮询 Gmail 的联系人列表,以便在用户输入电子邮件地址时可以“自动填充”。
我应该拆分这个类,还是应该这样做:
1)将客户端联系人列表下载到磁盘
2)在我的to/cc/bcc字段上有一个击键方法,对于输入的每个字符都会轮询GmailAccount.FindContact()方法看看是否有匹配的?
3) 如果匹配,则传递完整地址。
感谢您的帮助!
I'm writing an application,
The main purpose of the application is to be able to rapidly send emails using one's Gmail account (NOT reading emails, just sending).
I have a "GmailAccount" class which creates an SmtpClient object within its constructor using the user's Username and Password. It also has a "Send" method which takes a MailMessage that is going to be built by my UI and passed over.
The problem I have, is that I would quite like to also poll Gmail's contact list so that I can 'autofill' when the user is typing email addresses.
Should I split this class up, or should I also do this:
1) Download client contact list to disk
2) Have a keystroke method on my to/cc/bcc fields that for every char typed polls the GmailAccount.FindContact() method to see if there is a match?
3) If there's a match, pass the full address over.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这一切都与什么适合您以及您的(整个)应用程序如何工作有关。
就我个人而言,我会将联系人放在
GmailAccount
下,因为这些联系人是 Gmail 帐户的一部分。您可能不同意,但您这样做是完全正确的,因为类设计是主观的。我见过许多类设计,它们具有单个属性和类,然后其中有另一个类+一个字段。该程序的作者可能会觉得这样做很好,但我个人不同意他的类设计。事实是,我们都是对的。
It's all about what's appropriate to you, and how your (whole) application works.
Personally, I'd have the contacts under
GmailAccount
, because the contacts are part of the Gmail account. You may disagree, and you are completely correct in doing so, because class design is something subjective.I've seen many class designs which have a single property and have class, which then has another class + one field in them. The author of that program may find it good to do so, but I would personally disagree with his class design. Thing is, we are both correct.