本文介绍了人们做了什么来避免紧耦合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 采用n层 系统的项目层次结构解决方案,以便我们拥有数据层,业务层和表示层。 表示层耦合到业务层,业务 层耦合到数据层。到目前为止一直很好。 假设数据层引发一个事件,它将Me(发送者)作为 对象和e(MyEventArgs, EventArgs的后代)到上面的层 (业务层)。假设业务层需要将此事件传递给表示层。它将我作为一个对象发送,但它是什么 它发送e作为?它不能作为MyEventArgs发送它,因为演示文稿 层对此类事物一无所知。我们可以将表示层 耦合到数据层,这样它就知道MyEventArgs是什么,但肯定是是禁止的。 我们还可以将MyEventArgs的定义删除到另一个项目 哪一切都是耦合的,但是现在这个常见的项目面临着 的危险各种特定于个人的东西的折衷组合 项目。 我们可以定义MyEventArgs的业务层版本 - 实际上是 与数据层中的一个相同 - 并且在传递之前将每个元素复制到新的对象,但这是很多打字,现在我们有了 重复。 我很想知道其他人在这种情况下做了什么。 CharlesTake a solution with a project hierarchy along the lines of an n-tiersystem, so that we have a data layer, business layer and presentation layer.The presentation layer is coupled to the business layer, and the businesslayer is coupled to the data layer. So far so good.Suppose the data layer raises an event, and it passes Me (the sender) as anobject, and e (MyEventArgs, a descendent of EventArgs) to the layer above(the business layer). Suppose also that the business layer needs to passthis event on to the presentation layer. It sends Me as an object, but whatdoes it send e as? It can''t send it as MyEventArgs because the presentationlayer knows nothing of such things. We could couple the presentation layerto the data layer, so that it knows what a MyEventArgs is, but surely thatis a no-no.We could also remove the definition of MyEventArgs to another project towhich everything is coupled, but now this common project is in danger ofbeing an eclectic mix of stuff that is really specific to individualprojects.We could define a business layer version of MyEventArgs - which is actuallyidentical to the one in the data layer - and copy each element to the newobject before passing it on, but that is a lot of typing, and now we haveduplication.I am interested to hear what other people do in this situation.Charles推荐答案 也许你应该就此止步。而不是将一个对象(或者更多的是具体的b $ b)传递回业务层,为什么不将一个 不同的对象或只是数据传递到业务层呢使用?Perhaps you should stop there. Rather than passing an object (or morespecifically itself) back to the business layer, why not pass either adifferent object or just data to the business layer for it to consume? 这篇关于人们做了什么来避免紧耦合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-01 02:54