简体   繁体   English

SOA(ish)架构,在哪里放置公共代码?

[英]SOA (ish) architecture, where to place common code?

we have a soa-ish architecture which looks like this 我们有一个看起来像这样的soa-ish架构

frontend            ->domain A ->db 
frontend->business A->domain B ->db
frontend            ->domain C ->db
frontend            ->domain A ->db 
frontend->business B->domain B ->db
frontend            ->domain C ->db

other app A
other app B

we also have other applications which are not part of this soa stack. 我们还有其他应用程序不属于这个soa堆栈。

from time to time we have the following discussion/problem: 我们不时有以下讨论/问题:

"i have code in domain A that is also useful in domain B but not in business services - where should i put the stuff with its tests". “我在域A中的代码在域B中也很有用,但在业务服务中却没有 - 我应该把这些东西放在测试中”。

let's assume the code is very abstract and domain agnostic, something very generic that could also be used by the "other" applications outside of soa. 让我们假设代码是非常抽象的和域不可知的,非常通用的东西,也可以被soa之外的“其他”应用程序使用。

so the question is: 所以问题是:

a) put it in a "generic-domain-stuff" module which all domain inherit via maven dependencies. a)将它放在“generic-domain-stuff”模块中,所有域都通过maven依赖继承。 This will probably end up growing and growing until it is a mess…. 这可能最终会成长并增长,直到它变得一团糟......

b) create a module "generic-stuff" which can be used by soa and the "other" applications. b)创建一个模块“generic-stuff”,可以由soa和“其他”应用程序使用。 This will probably lead to a lot of small maven modules…. 这可能会导致许多小型maven模块......

c) duplicate the code until you have three use cases, then refactor to a) or b). c)复制代码,直到你有三个用例,然后重构为a)或b)。 This screems DRY (don't repeat yourself) 这是DRY的结果(不要重复)

i have people with 10+ years of "enterprise" experience around me but we never seem to find a proper solution/answer to the always same problems :) 我的人有10年以上的“企业”经验,但我们似乎从来没有找到适当的解决方案/答案总是同样的问题:)

i would be interested in hearing you experiences 我很想听听你的经历

(b) should be the way to go. (b)应该是要走的路。 If the code/logic is so generic then it is best fit for a library. 如果代码/逻辑是如此通用,那么它最适合库。 Application(s) needing this logic should use the library through maven (or any other dependency management mechanism). 需要此逻辑的应用程序应通过maven(或任何其他依赖关系管理机制)使用库。 You should not allow one library to become a "god library". 你不应该允许一个图书馆成为“神图书馆”。 Break the library into smaller cohesive pieces as time passes. 随着时间的推移,将图书馆分成更小的连贯片段。 That way you can prevent it from growing too big and becoming a mess. 这样你就可以防止它变得太大而变得一团糟。 Don't worry about many maven libraries - many small and cohesive libraries are better than one big monolithic "do it all" library. 不要担心许多maven库 - 许多小而有凝聚力的库比一个大的单片“do all all”库更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM