[英]OOP Design for a system for reading data from different sources and send it to different destinations
I am working on programming a java software that will be like a middleware for gathering data from different sources then process the data and send it to different destinations. 我正在编写一个java软件,它将像一个中间件,用于从不同的源收集数据,然后处理数据并将其发送到不同的目的地。
The data sources and destinations includes: files, database, TCP, HTTP. 数据源和目标包括:文件,数据库,TCP,HTTP。
The user will be able to create a channels, each channel will have one data source (file reader, database reader, tcp listener) and one or many data destinations (file writer, database writer, tcp sender). 用户将能够创建一个通道,每个通道将有一个数据源(文件读取器,数据库读取器,tcp监听器)和一个或多个数据目标(文件编写器,数据库写入器,tcp发送器)。
The application will work as following: 该应用程序将如下工作:
What comes in my mind is: 我想到的是:
So, is this the best way to represents the channels, sources and destinations? 那么,这是表示频道,来源和目的地的最佳方式吗? I think sources and destinations have a similarities, for example, FileReader and FileWriter classes will be the same except that one will be for reading and the other for writing, is it good to represent each of them as a separate class?
我认为源和目的地有相似之处,例如,FileReader和FileWriter类将是相同的,除了一个用于阅读而另一个用于写入,将它们作为一个单独的类表示是否很好?
That look ok. 那看起来不错。 If you look at some integration frameworks like Camel or Spring Integration, they have something very similar.
如果你看一些像Camel或Spring Integration这样的集成框架,它们会有类似的东西。 They also have different types of channels (p2p async, p2p sync and pub-sub) and transformers.
它们还有不同类型的通道(p2p async,p2p sync和pub-sub)和变换器。 I mention this 2 very mature frameworks in case you want to use them rather than to write your own (I strongly suggest you to take look at Camel, as that might provide exactly what you want).
我提到了这两个非常成熟的框架,以防你想要使用它们而不是自己编写(我强烈建议你看看Camel,因为它可能提供你想要的)。
About the question of Readers/Writers, I think it's definitely better to keep them as separate classes, as otherwise it might create confusion (is this class being used as a reader or writer?) and can prevent errors (someone configuring a reader, but injecting it as a writer). 关于读者/作者的问题,我认为最好将它们作为单独的类保留,否则它可能会造成混淆(这个类是用作读者还是作者?)并且可以防止错误(有人配置读者,但是把它作为一个作家注入)。
You might want to use a utility class shared between the reader and writer (or a delegate) to avoid duplicating code. 您可能希望使用读取器和编写器(或委托)之间共享的实用程序类来避免重复代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.