创建多个接口类以从不同的文件读取数据 [英] Create multiple interface class to read data from different file

查看:91
本文介绍了创建多个接口类以从不同的文件读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想创建一个结构,其中有一个具有2个功能的源类:GetData()作为Datatable和GetSchema()作为Datatable.调用此函数时,应根据所选文件的类型相应地转到界面之一,即如果选择了CSV,则转到CSV接口类,并从所选的CSV文件中获取数据和模式读取,否则,如果选择了ExcelFile,则应该调用SourceClass.GetData()并从Excel接口类中获取数据.

我想要实现的所有事情是,对SourceClass.GetData的调用将通过使用适当的接口类读取适当的文件来获取数据表,并且我不必将诸如FileName,FilePath,FileType,HasHeaderRow之类的任何值传递给它,连接字符串等...,因为接口类已经具有从...获取数据的所有信息.

我对此并不陌生,因此不胜感激,因此,我希望通过一些示例来说明如何实现这一目标....

非常感谢.

解决方案

我认为您正在寻找的是工厂方法模式 [ ^ ].有一个 C#示例 [此链接 [ 解决方案

I think what you are looking for is The factory Method Pattern[^]. there is a C# example[^] if you scroll down enough.

A note on terminology: what you are looking for is a pattern where you have different implementations of the same interface, using different details to accomplish the same abstract tasks. not two different interfaces...


Just went over my head :( :( Can you please elaborate in vb.net language as I have no idea about c# :( :(


This link[^] has a vb example.


这篇关于创建多个接口类以从不同的文件读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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