- 最後登錄
- 2023-5-8
- 在線時間
- 7 小時
- 註冊時間
- 2011-12-1
- 閱讀權限
- 20
- 精華
- 0
- UID
- 10604124
- 帖子
- 294
- 積分
- 47 點
- 潛水值
- 16940 米
| 回覆中加入附件並不會使你增加積分,請使用主題方式發佈附件。 本帖最後由 ggnnyy 於 2018-6-20 10:49 PM 編輯
各位大大好:
想請問以下兩種程式碼實作的差別以及優缺點??- public class EmailService
- {
- public void SendMessage()
- {
- //...
- }
- }
- public class NotificationSystem
- {
- private EmailService svc;
- public NotificationSystem()
- {
- svc = new EmailService();
- }
- public void InterestingEventHappend()
- {
- svc.SendMessage();
- }
- }
複製代碼 以及以下沒有用構造函數創建- public class EmailService
- {
- public void SendMessage()
- {
- //...
- }
- }
- public class NotificationSystem
- {
- private EmailService svc = new EmailService();
- public void InterestingEventHappend()
- {
- svc.SendMessage();
- }
- }
複製代碼
... |
|