Applying Clean Architecture Principle When Add Dashboard module witch query multiple services from Application Layer

huangapple go评论56阅读模式
英文:

Applying Clean Architecture Principle When Add Dashboard module witch query multiple services from Application Layer

问题

我在询问如何在不违反SOLID原则和一般的干净架构原则的情况下,最佳方式将仪表板模块添加到应用软件中。

我的第一个想法是添加一个层次(仪表板层次),负责从应用层面收集所有统计信息,但我注意到仪表板层次将有超过一个变更原因,这违反了SRP,换句话说,仪表板层次将受到以下影响:
1- 仪表板的主要用户(经理)的新要求,这是预期的。
2- 来自其他模块的用户,我们从中收集统计信息,例如注册模块。
因此,来自经理或注册模块的任何更改都将影响仪表板层次。

英文:

I am asking about the best way to add dashboard module to application software without violating the SOLID principle and clean Architecture principle in general.

My first though is to add layer(Dashboard layer) with is responsible for gathering all statistics from the application layer,
but what I notice is Dashboard layer will have more than one reason to change which violate the SRP, in other word the Dashboard layer will be affected by:
1- the dashboard main user (manager) new requirements which is expected.
2- the users of the other modules which we gather the statistics from e.g. Registration module.
as a result, any change from the manager or the Registration module will affect the dashboard layer.

答案1

得分: 1

快速回应 Applying Clean Architecture Principle When Add Dashboard module witch query multiple services from Application Layer

如果我理解正确,您需要做的是一个报告模块,它需要读取应用程序的一些数据。
您所谓的"仪表板层"可能只是您想要添加到应用程序的新模块。

一些开发人员可能会迅速引入一个新的应用程序,这将成为主要应用程序的报告工具。
这不是坏主意,但如果您只需要1或2个仪表板呢?

我建议您从引入一个新模块开始。

  1. 它不是领域的一部分。
    您所做的不是领域的新部分。也许您在应用程序中处理了许多领域,而此仪表板需要访问所有这些领域的数据。

  2. 它不是基础设施的一部分,因为它不是一个依赖项。

  3. => 它在另一侧。

这个模块就像未来仪表板前端应用程序的新后端,它将消耗您的数据。

这个模块的责任只是聚合数据,也许是转换数据。
如果您觉得这种事情可以在显示仪表板的前端应用程序中完成,那就开始像那样做吧(如果使用您已经有的现有API可以满足您的需求,并且响应时间可以满足您的需求)。
不要想象还不存在的一些要求。
当您感到事情在变化,需要引入后端来支持这个报告工具时,请继续进行。
也许它将负责进行这种聚合,也许将数据持久化以使读取它们更加优化...

您所需的要求的结论就像是您应用程序的查询模块。
它与应用程序的领域没有任何关系。
最好将这部分明确纳入您的架构,而不是迅速创建一个新的应用程序。
当您觉得是分离的时候,再去做吧 Applying Clean Architecture Principle When Add Dashboard module witch query multiple services from Application Layer

英文:

A quick response Applying Clean Architecture Principle When Add Dashboard module witch query multiple services from Application Layer

If I understood what you need to do is a Reporting module which will need to read some data of your application.
What you call Dashborad layer may be just a new module that you want to add to the application.

Some developers will go quickly to introduce a new Application which will be a Reporting tool of the main one.
Which is not bad idea, but what if all what you need is just 1 or 2 dashboards ?

I advise you to start by introducing a new module in your Application.

  1. It is not a part of the Domain.
    What you are doing is not a new part of the domain. May be you are handling many domains in the application and this dashboard need to access all
    the data of all these domains.

  2. It is not a part of the infrastructure because it is not a dependency.

  3. => It is in the other side.

This module is like a new Backend for future Front Application of your dashboards which will consume your data.

The responsability of this module is only agregating and may be transforming data.
If you fill that this kind of thing may be done in the Front Application that display dashboards, let's go and start doing it like that. (if consuming the existing Api that you already have fill your need, and time response fill your need)
Do not imagine some requirements that are not yet present.
And when you feel that things are changing and you need to introduce a Backend for this reporting tool go for it.
May be it will responsible to make this kind of aggregation, may persisting data to make reading them more optimized...

The conclusion that the requirement that you have is like a Query Module of your application.
It doesn't have any relation with the domain of the Application.
It will be nice to make this part a clear part in your Architecture without going quickly to create a new Application.
And when you feel it is time to separate it, do it Applying Clean Architecture Principle When Add Dashboard module witch query multiple services from Application Layer

答案2

得分: 0

你在这里混合了不同的概念。一个层包含多个模块(不仅仅是一个)。它们都有类似的责任。例如,MVC中的View层包含了View模块。

在开始适当建模之前,您需要将您的需求分解成更小的部分。

例如,一个需求可以是:管理员可以添加报告。
为了满足这个需求,您将需要一个管理员实体、一个报告实体,以及一个添加报告的应用程序服务。

我发现,当我进行领域驱动设计时,从我的工作中会自然而然地发展出一种自然的层次结构,但领域驱动设计和层次结构并不是互斥的。

英文:

You are mixing different concepts here. A Layer contains several modules (not just one). They'll all have similar responsibilities. For example, the View layer in MVC contains View modules.

You need to break down your requirements into smaller ones before starting to Model it out adequately.

For example, one requirement could be: Admins can Add Reports.
For this requirement, you'll need an Admin Entity, a Report Entity, and an Application Service that Adds report.

I find that when I do DDD, there's a natural Layer architecture that'll develop from my work but DDD and Layers are not mutually exclusive.

答案3

得分: 0

即使仪表板会显示许多不同的内容,每个内容都不是仪表板的责任。仪表板负责将不同的项目放置在不同的位置并管理此布局。项目必须使用插件机制来连接到仪表板。

取决于您使用的技术,这些插件机制的实现方式可能会有所不同,但一般结构始终相同。您必须将依赖关系从仪表板反转到不同的项目上。

我通常使用术语"视图站点"。视图站点是可以安装视图的位置。仪表板将为其他模块可以安装视图的位置定义视图站点。我称负责定义视图站点的类为"视图布局"。仪表板必须使用查找机制来查找"视图站点贡献"。视图站点贡献是插件,插入到视图站点中。在仪表板发现所有这些贡献后,它会调用每个"视图站点贡献"并将视图站点传递给它。通常,每个"视图站点贡献"都有一个标识符,而仪表板只知道标识符A应安装在视图站点B上。这就是我所说的仪表板的责任是管理它显示的项目时的意思。

我最近发布了一个关于这个主题的git存储库。示例是用Java Swing完成的,但其背后的概念也可以应用于任何其他技术 - 我猜。也许我将来会发布一个基于React的示例。

如果您使用Web技术,您可能还会对Micheal Geers的书《Micro Frontends In Action》感兴趣。

英文:

Even the dashboard will show a lot of different things, each of the things is not the responsibility of the dashboard. The dashboard is responsible for placing the different items at different locations and the management of this layout. The items must use a plug-in mechanism to hook into the dashboard.

It depends on the technologies you use how those plug-in mechanisms are implemented, but the general structure is always the same. You must inverse the dependencies from the dashboard to the different items.

I usually use the term "view site". A view site is a location where a view can be installed into. The dashboard will define view sites for the locations where other modules can install views into. I call the class that is responsible for defining view sites a "view layout". The dashboard must use a lookup mechanism to find "view site contributions". view site contributions are the plug-ins that plug into a view site. After the dashboard has discovered all it calls each "view site contribution" and passes it a view site. Usually each "view site contribution" has an identifier and the dashboard only knows that identifier A should be installed at view site B. This is what I mean when I say the dashboard's responsibility is the management of the items it displays.

I recently published a git repository that is about this topic. The example is done in Java Swing, but the concept behind it can be applied to any other technologies too - I guess. Maybe I will publish an React based example in the future.

If you are using web technologies you might also be interessted in the book "Micro Frontends In Action" by Micheal Geers.

huangapple
  • 本文由 发表于 2023年7月14日 03:14:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682573.html
  • clean-architecture
  • dashboard
  • domain-driven-design
  • single-responsibility-principle
  • solid-principles
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定