DDD:實體如何處理外部依賴

場景

修改用戶名時,要驗證用戶名的唯一性。

實現1

1 public class User
2 {
3       public void ChangeUsername(string newUsername)
4       { 
5               //使用服務定位器獲取IUsernameUniqueService ,執行驗證。
6       }
7 }

實現2

 1 public class User
 2 {
 3         public void ChangeUsername(string newUsername)
 4         { 
 5             EventBus.Send(new  UsernameChangedEvent(newUsername));
 6         }
 7 }
 8  
 9 public class UsernameChangedEventHandler
10 {
11         public UsernameChangedEventHandler(IUsernameUniqueService usernameUniqueService){}
12  
13         public void Process(UsernameChangedEvent){} 
14 }

實現3

 1 public class ChangeUsernameCommandHandler
 2 {
 3         public ChangeUsernameCommandHandler(IUsernameUniqueService usernameUniqueService){}
 4 
 5         public void Process(ChageUsernameCommand){}
 6 }
 7 
 8 public class User
 9 {
10         public void ChangeUsername(IUsernameUniqueService usernameUniqueService, newUsername){}
11 }

實現4

 1 public class UsernameChangeService
 2 {
 3       public UsernameChangeService(IUsernameUniqueService usernameUniqueService){}
 4 
 5       public void ChangeUsername(Guid userId, string newUsername){ }
 6 }
 7 
 8 public class User
 9 {
10       Internal void ChangeUsername(string newUsername){ }
11 }

實現5

 1 public class UsingUser
 2 {
 3       public UsingUser(User user, IUsernameUniqueService usernameUniqueService){}
 4        
 5       public void ChangeUsername(string newUsername){ }
 6 }
 7 
 8 public class User
 9 {
10       Internal void ChangeUsername(string newUsername){  }
11 }

備注

到底用哪一個,先不做評判。

轉載于:https://www.cnblogs.com/happyframework/archive/2013/03/26/2983927.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274311.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274311.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274311.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

架構師論壇 創業_我在早期創業時作為設計師學到的東西

架構師論壇 創業For over 2 years at a young product company, I collaborated with talented engineering folks for a 0 → 1 suite of products. Here are my learnings and key takeaways. Of course, these are my views and do not represent those of my employers or …

HFileOutputFormat與TotalOrderPartitioner

最近需要為一些數據增加隨機讀的功能,于是采用生成HFile再bulk load進HBase的方式。 運行的時候map很快完成,reduce在sort階段花費時間很長,reducer用的是KeyValueSortReducer而且只有一個,這就形成了單reducer全排序的瓶頸。于是…

qt按鈕禁用和激活禁用_為什么試探法只是經驗法則:禁用按鈕的情況

qt按鈕禁用和激活禁用Most user experience designers will be familiar with Jackob Nielsen’s 10 usability heuristics. They are widely cited and a great set of broad rules of thumb to follow when designing user interfaces.大多數用戶體驗設計師將熟悉Jackob Niel…

Teach Yourself Java 2 in 21 Days 書中樣例代碼實踐

找了好幾書JAVA的書,看了幾章,都看不下去。 我覺得適合《Teach Yourself Java 2 in 21 Days》(Rogers Cadenhead Laura Lemay)還是適合我的。 孫衛琴那本,我感覺就羅嗦多了沒到我點子上。 接口,抽象類這些內…

好奇心機制_好奇心問題

好奇心機制For my past two jobs I’ve posted a question every week in my team chat and learned so much about my co-workers. Give it a try! :D對于過去的兩個工作,我每周都會在團隊聊天中發布一個問題,并且對我的同事了解很多。 試試看&#xff…

20130328java基礎學習筆記-循環結構for以及for,while循環區別

1.循環結構:for講解class ForDemo{ public static void main(String[] args) { /* for(初始化表達式;循環條件表達式;循環后的操作表達式) { 執行語句;(循環體) } */ for(int x 1; x<3; x) { …

小程序設計避免犯什么錯_新設計師犯下的5種印刷錯誤以及如何避免

小程序設計避免犯什么錯Over the last year and a half, I’ve had the opportunity to teach the basics of typography to undergraduate graphic design students. During this time, I’ve noticed some common mistakes that my students make when first learning how to…

移動設備web文字單位_移動設備如何塑造現代Web設計

移動設備web文字單位I was working with a nonprofit earlier this month on redesigning their website and during the first meeting, I proposed a very standard idea: the home page needed to tell a story and guide the intended user through the intended process (…

hp-ux修改時區方法_UX研究人員可以倡導人類的6種方法

hp-ux修改時區方法In the UX world, we often hear terms like “user-centered,” “human-centered,” and “customer-centered.” We believe that in order to be innovative, we need to center experiences that are authentic, intuitive, and practical.在UX世界中&am…

2013年3月百度之星A題

偽隨機數生成器 題目描述 baidu熊最近在學習隨機算法&#xff0c;于是他決定自己做一個隨機數生成器。 這個隨機數生成器通過三個參數c, q, n作為種子, 然后它就可以通過以下方式生成偽隨機數序列&#xff1a; m0 c, mi1 (q2mi 1) mod 2n, for all i > 0. 因為一些奇怪的…

為什么張揚的人別人很討厭_為什么每個人總是討厭重新設計,即使他們很好

為什么張揚的人別人很討厭重點 (Top highlight)微處理 (Microprocessing) In Microprocessing, columnist Angela Lashbrook aims to improve your relationship with technology every week. Microprocessing goes deep on the little things that define your online life to…

轉載--C語言:浮點數在內存中的表示

單精度浮點數&#xff1a; 1位符號位 8位階碼位 23位尾數 雙精度浮點數&#xff1a; 1位符號位 8位階碼位 52位尾數 實數在內存中以規范化的浮點數存放&#xff0c;包括數符、階碼、尾數。數的精度取決于尾數的位數。比如32位機上float型為23位 double型為52位。…

學習ui設計_如果您想學習UI設計,該怎么辦

學習ui設計There is a question that is always asked when we want to learn something new.當我們想學習新東西時&#xff0c;總會問一個問題。 Where to start?從哪兒開始&#xff1f; This is also being my question when I want to learn UI design. In this article, …

Christmas

html5 game - Christmasloading......轉載于:https://www.cnblogs.com/yorhom/archive/2013/04/05/3001116.html

30個WordPress Retina(iPad)自適應主題

原文地址&#xff1a;http://www.goodfav.com/zh/retina-ready-wordpress-themes-3556.html WordPress Retina定制主題進行了優化&#xff0c;支持Retina屏幕上的高品質和清晰的圖像。如果你關心這個話題&#xff0c;又不知道這究竟是什么&#xff0c;那么請你繼續閱讀。 wordp…

Thinking in java第一章對象導論

這一章&#xff0c;做筆記感覺不是很好做。每個人又每個人對面向對象的理解。這里說一下書里的關鍵字&#xff0c;穿插一下自己的思想 面向對象的編程語言里面很流行的一句話&#xff0c;一切都是對象。面向對象的核心就是抽象&#xff0c;抽象的能力有大有小&#xff0c;是決定…

Android SlidingMenu插件的使用

1、在github上下載了源碼后 不知道如何使用&#xff0c;在折騰了一個晚上后終于弄好了 下載地址 https://github.com/jfeinstein10/SlidingMenu 下載完后&#xff0c;解壓&#xff0c;然后先import 其中的library &#xff0c;然后把項目名改為SlidingMenu 2、然后再到http…

css 字體字體圖標_CSS基礎知識:了解字體

css 字體字體圖標In this tutorial, we’ll be learning about working with fonts in CSS!在本教程中&#xff0c;我們將學習有關在CSS中使用字體的知識&#xff01; The font property is a shorthand property which can combine a number of sub-properties in a single d…

openstack quantum搭建過程中一些有用的鏈接

OpenvSwitch的概念和流程&#xff1a; http://blog.wachang.net/2013/03/openvswitch-fullbook-2-workflow-1/ OpenvSwitch的vlan模式&#xff1a; http://openvswitch.org/support/config-cookbooks/vlan-configuration-cookbook/ OpenvSwitch問答&#xff1a; http://openvsw…

mysql下載哪一代版本好_潮一代更好的設計

mysql下載哪一代版本好I think we can all agree that quarantined life has been strange. And while most of the day is comprised of the monotony of domestic life, I’ve been surprised at how much of my time is dominated by technology.我認為我們都可以同意隔離的…