设计问题:电话是拨打电话号码,还是电话号码在电话上自行拨号? [英] Design question: does the Phone dial the PhoneNumber, or does the PhoneNumber dial itself on the Phone?

查看:88
本文介绍了设计问题:电话是拨打电话号码,还是电话号码在电话上自行拨号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从我在DDD Yahoo!上发布的内容重新发布的.组.

This is re-posted from something I posted on the DDD Yahoo! group.

在所有条件都相同的情况下,您是写phone.dial(phoneNumber)还是phoneNumber.dialOn(phone)?请记住将来可能的要求(除了电话号码之外的帐号,除了电话之外的计算器).

All things being equal, do you write phone.dial(phoneNumber) or phoneNumber.dialOn(phone)? Keep in mind possible future requirements (account numbers in addition to phone numbers, calculators in addition to phones).

选择倾向于说明信息专家,单一责任原则和告诉不要问的习惯用法彼此矛盾.

The choice tends to illustrate how the idioms of Information Expert, Single Responsibility Principle, and Tell Don't Ask are at odds with each other.

phoneNumber.dialOn(phone)支持信息专家和告诉不要问,而phone.dial(phoneNumber)支持单一责任原则.

phoneNumber.dialOn(phone) favors Information Expert and Tell Don't Ask, while phone.dial(phoneNumber) favors Single Responsibility Principle.

如果您熟悉Ken Pugh在Prefactoring中的工作,这是电子表格难题;您要添加行还是列?

If you are familiar with Ken Pugh's work in Prefactoring, this is the Spreadsheet Conundrum; do you add rows or columns?

推荐答案

选择是否为列对象或行对象提供Dial方法不会改变程序的缩放比例.

Choosing whether to give the column objects or the row objects the dial method doesn't change how the program will scale.

dial方法本身就是行和列方法的序列.您必须问这些方法依赖什么.

The dial method is just going to be itself a sequence of row and column methods. You have to ask what those methods depend on.

如果行方法的顺序不完全取决于所涉及的列对象(但确实取决于所涉及的特定行对象),并且列方法的顺序反之亦然,那么问题将扩展为m + n(m =数行,n =数列).创建新行时,如果为列方法分配了拨号"方法,那么它实际上不会为您节省任何工作.您仍然必须指定行方法的唯一序列,以便在某处的拨号"中使用!

If the sequence of row methods doesn't depend on knowing exactly which column object is involved (but does depend on which particular row object is involved) and vice versa for the sequence of column methods, then the problem scales as m + n (m = num. rows, n = num. cols). When you create a new row it doesn't actually save you any work had the column method been assigned the 'dial' method. You still have to specify a unique sequence of row methods for use in 'dial' somewhere!

但是,如果说拨号"中的列方法序列甚至不取决于所涉及的 column 对象(它们使用一个通用"列方法序列),则问题只是扩展到m.您是否已将拨号"方法分配给列对象实际上并不重要,程序仍将缩放为m;添加更多的列对象时,基本上不需要做任何工作来制作新的拨号方法,并且您显然可以选择将所有这些拨号方法本身抽象为一个通用的拨号方法.

If, however, say the sequence of column methods inside 'dial' doesn't even depend on which column object is involved (they use one 'generic' sequence of column methods), then the problem just scales as m. It doesn't actually matter if you've assigned the 'dial' method to the column objects, the program still scales as m; essentially no work is required to make a new dial method when adding 1 more column object and you clearly have the option of abstracting all those dial methods themselves into one generic dial method.

这篇关于设计问题:电话是拨打电话号码,还是电话号码在电话上自行拨号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆