vb.net - Best way to future proof software that opens files with default application interactively -


i have created vb .net application opens files in default application - extracts information , returns listview on form.

all of code in main form. main form has in it

  • imports microsoft.office.core
  • imports microsoft.office.interop.word
  • imports microsoft.office.interop.excel

if in future want modify software include filetype not thought of in release, better off of filetypes wish open (including office) adding new classes each filetype , including 'imports' in individual classes?

so example have:

  • openfiledwg.vb
  • imports autodesk.autocad.runtime

  • openfiledoc.vb

  • imports microsoft.office.interop.word

etc. etc. standard approach? if this, use:

if exists lcase(my.computer.filesystem.getfileinfo(filepath).extension) strfileopener = openfiledwg & extension private fileopener strfileopener

would approach work, or still need reference .dll in main application, making approach unworthy?

if use approach, give .vb file part of update?

any advice appreciated.

seems me classing case use factory design pattern

basically, factory design pattern provides loose coupling between factory created classes , class uses them.

begin separating different file types different classes, , have them inherit basic abstract class (mustinherit in vb.net).
create factory class create create concrete implementation of every file reader class. (meaning each file type).

i'll try illustrate simple example:

'' defines abstract class filereaders should inherit public mustinherit class filereader    public mustoverride function readfilecontent(path string) string end class 

now, of classes reading files must inherit filereader class:

public class wordfilereader    inherits filereader     public override function readfilecontent(path string) string    '' todo: add code read content of word document , return string.    end function end class  public class excelfilereader    inherits filereader     public override function readfilecontent(path string) string    '' todo: add code read content of excel file , return string.    end function end class 

then can use simple factory method (read here learn difference between factory methods , abstract factories) create classes:

enum filetypes     word,     excel end enum  public function getfilereader(filetype filetypes) filereader     dim filereader filereader = nothing     select case filetype         case filetypes.word:             filereader = new wordfilereader()         case filetypes.excel:             filereader = new excelfilereader()     end select     return filereader  end function 

to enable new file types add-ins can use mef load concrete classes.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -