c# - Cleaning up FileInfo.name switch/case statement with an interface -


i have following:

foreach(var file in today.getfiles()) {     if(file.length > 0 && file.extension == ".txt")     {         switch (file.name)         {             case "realy_long_ugly_file_name_0":                 //do                 break;             case "realy_long_ugly_file_name_1":                 //do else                 break;         }     } } 

i have come across this post , thought clean code using interface. right application situation? have set interface , inheritance don't quite know how proceed.

i understand interface calling different class based on ipizza member in ilist<ipizza>. have hard time understanding how can pass in file.name (formerly done switch/case) interface call different classes.

interface imyfiles {     void process(fileinfo file); }  public class filename0 : imyfiles {     void imyfiles.process(fileinfo file)     {         //do somthing specific filename0     } }  public class filename1 : imyfiles {     void imyfiles.process(fileinfo file)     {         //do somthing specific filename1     } } 

what aiming here encapsulate different types of processing based on files own objects.

these options see:

  1. imyfiles objects decide process(you can having if @ start of methods concrete implementations). make collection classes imyfiles , call process until knows needs pick up.
  2. create factory using switch statement returns instance of imyfile , call process. way decision of am(construction) , can do(are separate).

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -