一个常见的架构问题 [英] A common architectural problem

查看:116
本文介绍了一个常见的架构问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




假设有一个方法调用另一个方法,该方法也调用其他方法,等等有一个冗长的方法树。如果事实证明一切都必须中止,我该怎么办?我在这里看到的唯一合理的方法是使用异常,但每个人都告诉异常不应该用于控制流程。我只是想不出另一种合理的方法来解决这个问题。


有没有好书教会如何做出伟大的建筑?


提前谢谢

Frank

Hi,

Assuming having a method that calls another method which also calls other methods and so on having a long winded tree of methods. What do I do in case it turns out everything has to be aborted? The only reasonable way I see here is to use a exception but everybody is telling exceptions should not be used for control flow. I just can''t think of another reasonable way to deal with this.

Are there any good books that teach how to do great architecture?

thanks in advance
Frank

推荐答案

Hello stax,


这绝对是一个有争议的问题。虽然经验法则。例外是

例外情况。它们应该只用于意外情况,例如对方法输入无效的

或者不点击的某些infrstructure位(比如打开数据库

连接等)。抛出异常有点贵并且最小化抛出

异常会对您的性能产​​生积极影响。


对于成功/失败指示,您应该使用返回值。


-

Patrik L?wendahl [C#MVP]
http://www.lowendahl.net
http://www.cornerstone.se

Hello stax,

This is definatly a debated issue. A rule of thumb though. Exceptions are
Exceptions. They should really only be used for unexpected cases, like invalid
input to a method or some infrstructure bits not clicking (like opening databse
connections etc). Throwing exceptions is a bit expensive and minimizing thrown
exceptions will affect your performance positivly.

For success/failure indication you should use return values.

--
Patrik L?wendahl [C# MVP]
http://www.lowendahl.net
http://www.cornerstone.se



假设有一个方法调用另一个也调用的方法
其他方法等等有一个冗长的方法树。如果事实证明一切都必须中止,我做了什么?我在这里看到的唯一合理方法是使用异常,但每个人都在告诉异常不应该用于控制流程。我无法想出另一种合理的方法来解决这个问题。

是否有任何好书教会如何做好建筑?

谢谢提前
弗兰克
Hi,

Assuming having a method that calls another method which also calls
other methods and so on having a long winded tree of methods. What do
I do in case it turns out everything has to be aborted? The only
reasonable way I see here is to use a exception but everybody is
telling exceptions should not be used for control flow. I just can''t
think of another reasonable way to deal with this.

Are there any good books that teach how to do great architecture?

thanks in advance
Frank



我不知道你的情景如何,但也许是班级

System.Transactions.TransactionScope和

System.Transactions.DependentTransaction在你需要回滚的情况下对你来说很有用。此类是.NET 2.0的新增功能。


" stax" < _r ************************ @ yahoo.de>在留言中写道

news:dq ********** @ online.de ...
I don''t know how you scenario looks like, but maybe the class
System.Transactions.TransactionScope and
System.Transactions.DependentTransaction would be of a good use to you in
case you need to rollback. This class is new to .NET 2.0.

"stax" <_r************************@yahoo.de> wrote in message
news:dq**********@online.de...


假设有一个方法调用另一个方法,该方法也调用其他方法等等,有一个冗长的方法树。我怎么办
情况结果一切都必须中止?我在这里看到的唯一合理的方法是使用异常,但每个人都在告诉异常,不应该用于控制流程。我只是想不出另一种合理的方式来解决这个问题。

是否有任何好书教会如何做出伟大的建筑?

谢谢提前
Frank
Hi,

Assuming having a method that calls another method which also calls other
methods and so on having a long winded tree of methods. What do I do in
case it turns out everything has to be aborted? The only reasonable way I
see here is to use a exception but everybody is telling exceptions should
not be used for control flow. I just can''t think of another reasonable way
to deal with this.

Are there any good books that teach how to do great architecture?

thanks in advance
Frank



>对于成功/失败指示,你应该使用返回值。


我搜索了很多但是找不到东西所以也许你或其他人可以指点我一些资源。返回值的问题是它添加了很多样板代码,因为必须为每个方法调用检查返回值。我的应用程序正在进行非常漫长的处理。这种方法的问题通常是我想返回一些类型而不是布尔返回值,我对全局变量或ref参数不太满意。
> For success/failure indication you should use return values.

I searched quite a bit but didn''t find something so maybe you or somebody else can point me to some resources. The problem with return values is it adds a lot boilerplate code as the return value has to be checked for every method call. My application has a really long winded processing going on. Problems with this approach are often I want to return some types instead of a boolean return value and I''m not very comfortable with global variables or ref parameters.


这篇关于一个常见的架构问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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