首页 分享 Remove Middle Man · Los Techies

Remove Middle Man · Los Techies

来源:花匠小妙招 时间:2025-08-14 20:52

28 August, 2009. It was a Friday.

Today’s refactoring comes from Fowler’s refactoring catalog and can be found here.

Sometimes in code you may have a set of “Phantom” or “Ghost” classes. Fowler calls these “Middle Men”. Middle Men classes simply take calls and forward them on to other components without doing any work. This is an unneeded layer and can be removed completely with minimal effort.

1: public class Consumer

2: {

3: public AccountManager AccountManager { get; set; }

4: 

5: public Consumer(AccountManager accountManager)

6: {

7: AccountManager = accountManager;

8: }

9: 

10: public void Get(int id)

11: {

12: Account account = AccountManager.GetAccount(id);

13: }

14: }

15: 

16: public class AccountManager

17: {

18: public AccountDataProvider DataProvider { get; set; }

19: 

20: public AccountManager(AccountDataProvider dataProvider)

21: {

22: DataProvider = dataProvider;

23: }

24: 

25: public Account GetAccount(int id)

26: {

27: return DataProvider.GetAccount(id);

28: }

29: }

30: 

31: public class AccountDataProvider

32: {

33: public Account GetAccount(int id)

34: {

35: // get account

36: }

37: }

</div> </div>

The end result is straightforward enough. We just remove the middle man object and point the original call to the intended receiver.

1: public class Consumer

2: {

3: public AccountDataProvider AccountDataProvider { get; set; }

4: 

5: public Consumer(AccountDataProvider dataProvider)

6: {

7: AccountDataProvider = dataProvider;

8: }

9: 

10: public void Get(int id)

11: {

12: Account account = AccountDataProvider.GetAccount(id);

13: }

14: }

15: 

16: public class AccountDataProvider

17: {

18: public Account GetAccount(int id)

19: {

20: // get account

21: }

22: }

</div> </div>

This is part of the 31 Days of Refactoring series. For a full list of Refactorings please see the original introductory post.

相关知识

Remove Middle Man · Los Techies
los免抠元素
Private Part Lubricate Remove Odor Vagina Cleaning Yoni Detox Remove Odor Tightening Lotion Products For Women - Buy Vagina Products For Women vagina Cleaning yoni Detox Product on Alibaba.com
《使命召唤》手游Man O War-冰晶凝华介绍
Man 【美摄视界】:[首发]春天的使者.金鈴花(三)
【植物病理学系】Wong Sek Man (王锡民) 教授
Dia de los Muertos 发现差异矢量迷宫游戏与跳舞的骷髅。背景图片免费下载
running man全昭旻怎么了 曾被批抢镜再次收到万条恶评
上传数据插件 Easy Populate 遇到问题 ?langer=remove
Dia de los muertos 卡通装饰品,墨西哥死亡主题图案与传统 alebrije 风格的鸟类骨骼,鲜花和羽毛,墨西哥假期民间主题,矢量插图。 背景图片免费下载

网址: Remove Middle Man · Los Techies https://www.huajiangbk.com/newsview2260452.html

所属分类:花卉
上一篇: PlayStation3
下一篇: New ActionMailer

推荐分享