我对这个问题有点困惑:分层架构是否有用,没有像DI或Repository这样的设计模式? 我不是在谈论直接DI和存储库模式; 他们只是例子。 据我所知,我们主要使用分层架构来删除跨层的依赖关系; 但是没有使用上面提到的设计模式,我们只是编写对这些层的直接引用。 例如,如果我们有一个没有任何设计模式的逻辑层和数据库层,我们会严重耦合每一层。 有谁能解释一下?
I'm a little bit confused on this matter: is layered architecture useful without any design pattern like DI or Repository? I'm not talking about direct DI and Repository patterns; they are just examples. As per my knowledge, we use layered architecture mainly to remove dependencies across layers; but without using the above mentioned design patterns, we just code direct references to those layers. As an example if we have a Logic layer and Database layer without any design pattern, we heavily couple each layer. Can anyone explain this?
最满意答案
简单回答:是的。
更长的答案:分层架构几乎总是一个优秀开发人员的设计目标,无论他们正在做什么项目(假设一个足够规模的项目,至少+优秀的开发人员)。
分层架构在其最基本的概念上只是“分工”到“逻辑单元”......这听起来很像“方法”。 从技术上讲,你可以在main方法中的单个类中编写一个完整的10,000行java程序......但显然,将程序细分为包,类和方法是有益的(无论你做出什么其他设计决策)关于类似代码的分组(我在这里非常广泛)。 所以多层拱门。 只是帮助将应用程序划分为不同“部分”的另一个“抽象”级别。
即使不使用DI等,设计应用程序以使用一组接口来定义不同组件之间的交互,不仅可以帮助您开发不同层的替代实现(这样可以通过几行代码轻松更改)在最终集成/合并之前进行测试)但它也将帮助您更好地精心设计项目。 这更像是一种“经验”的东西,但是像mutli-layers这样有一个很好的指导方针可以帮助您更快地决定哪些部分应该成为哪些层的一部分等。
当您合并每个人的代码时,它还可以帮助您分配工作量并减少问题数量。 例如,在我的本科软件工程课程中,我们设计了一个3层程序,我们使用ui,逻辑,存储作为我们的3层,除了定义代码的3个部分之外,我们然后能够在工作组之间划分工作量并最终组合我们的不同部分有0麻烦。
Simple answer: Yes.
Longer answer: Layered Architecture is almost always a design goal of a good developer, regardless of what project they are working on(assuming a project of sufficient size at least + good developer).
Layered Architecture at its most fundamental concept is just "division of labor" into "logical units"... which sounds a lot like 'methods'. Technically you can write an entire 10,000 line java program in a single class inside the main method... but obviously it is beneficial(regardless of what other design decisions you make) to sub-divide your program into packages, classes, and methods based on grouping of similar code(I'm being VERY broad here). So multi-layered arch. is just another level of 'abstraction' to assist in dividing an application into different 'parts'.
Even without the use of DI, etc. Designing your application to use a set of interfaces to define interactions between different components will not only assist you in developing alternative implementations of different layers(which would then be easy to change via a few lines of code for testing before final integration/merging) but it also will help you mentally design your project better. This is more of an 'experience' thing, but having a good guideline like mutli-layers helps you more quickly make the decisions of what parts should be part of which layers, etc.
It can also help with dividing the workload and reducing the number of issues when you go to merge everyone's code. For example, in my undergraduate software engineering course we designed a 3 layered program and we used ui, logic, storage as our 3 layers and besides defining 3 segments of the code, we were then able to divide the workload among the group and finally combine our different parts with 0 hassle.
更多推荐
发布评论