推荐程序结构 [英] Recommended program structure

查看:118
本文介绍了推荐程序结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一个初学者,我已经制定了一些想法,但要问社区即将实施以下方案的最佳方式:

as a beginner, I have formulated some ideas, but wanted to ask the community about the best way to implement the following program:

据解码8种不同类型的数据文件。他们都是不同的,但大多数是相似的(含有大量的类似的领域)。此外,还有3代系统,其可以生成这些文件。每个稍有不同,但产生相同类型的文件。

It decodes 8 different types of data file. They are all different, but most are similar (contain a lot of similar fields). In addition, there are 3 generations of system which can generate these files. Each is slightly different, but generates the same types of files.

我需要做出视觉应用程序,它可以在其中任何一个读,在表绘制数据(使用通过目前的数据表的DataGridView)绘制在图上了。

I need to make a visual app which can read in any one of these, plot the data in a table (using datagridview via datatable at the moment) before plotting on a graph.

有更多的是有点,但我的问题是关于基本结构。

There is a bit more to it, but my question is regarding the basic structure.

我很想了解更多关于做最好采用面向对象技术是否会适合很好。

I would love to learn more about making best use of object oriented techniques if that would suit well.

我使用C#(除非有更好的建议),主要是由于我缺乏经验和快速的开发时间。

I am using c# (unless there are better recommendations) largely due to my lacking experience and quick development time.

我目前使用的称为日志,知道哪一代/日志一班键入是开放的是文件。 IT控制阅读并出口到一个DataTable。然后表单可以给它一个路径,等待它处理文件,并要求数据表显示。

I am currently using one class called 'log' that knows what generation/log type the file that is open is. it controls reading and exporting to a datatable. A form can then give it a path, wait for it to process the file and request the datatable to display.

任何明显的改进?

推荐答案

正如你已经意识到有在这里建立一个非常优雅的面向对象的应用潜力很大。

As you have realised there is a great deal of potential in creating a very elegant OOP application here.

您的基本需要 - 因为我可以从你共享信息,请尽可能多的 - 是:

Your basic needs - as much as I can see from the information you have share - are:

1)识别文件类型的模块

1) A module that recognises the type of file

2),可以读取文件和数据加载到一个共同的结构(A模块,这将是共同的结构?)这是由处理器的

2) A module that can read the file and load the data into a common structure (is it going to be common structure??) this consists of handlers

3),可以可视化数据的模块

3) A module that can visualise the data

有关第一个,我会建议两种模式:

For the first one, I would recommend two patterns:

1a)的工厂模式:文件被传递到公共工厂和被解析到如此地步,它可以决定处理程序

1a) Factory pattern: File is passed to a common factory and is parsed to the point that it can decide the handler

2a)的链-of责任:文件被传递给知道,如果它可以支持文件或不每个处理程序。如果不能传递到下一个。在最后一方处理它拾起,如果最后一个处理程序无法处理它会出现错误。

2a) Chain-of-responsibility: File is passed to each handler which knows if it can support the file or not. If it cannot passes to the next one. At the end either one handler picks it up or an error will occur if the last handler cannot process it.

有关第二个,我建议设计一个共同的界面和每个处理程序执行常见任务,如加载,解析...如果可视化是不同的,具体的处理程序,那么你将有那些一套方法为好。

For the second one, I recommend to design a common interface and each handler implements common tasks such as load, parse... If visualisation is different and specific to handlers then you would have those set of methods as well.

不知道更多有关数据结构,我不能在可视化的部分评论。

Without knowing more about the data structure I cannot comment on the visualisation part.

希望这有助于。

更新

这是厂一 - 一个非常粗糙的伪代码:

This is the factory one - a very rough pseudocode:

Factory f = new Factory();
ILogParser parser = f.GetParser(fileName); // pass the file name so that factory inspects the content and returns appropriate handler
CommonDataStructure data = parser.Parse(fileName); // parse the file and return CommonDataStructure. 
Visualiser v = new Visualiser(form1); // perhaps you want to pass the refernce of your form
v.Visualise(data); // draw pretty stuff now!

这篇关于推荐程序结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆