I need some help with refactoring and ensuring that my design/structure is a) valid and b) the right one

I’m creating a document conversion application. Ideally, it should be able to receive just about any file and either reject it (not supported) or return a converted version (in most cases, convert from x to PDF). It will also have some Sharepoint features like downloading, uploading, versioning, etc, but that comes later. I wanted to create a standard way of converting but let classes perform their own logic and specific tasks, as the conversion logic can be significantly different for different filetypes. I also wanted to make sure that a Document has a specific set of properties and methods (mainly to help with Sharepoint integration).

An example would be to take an existing Word Document and return a PDF.

I’m not sure how to implement the part that decides which conversion class to use based on something like the original document’s file extension and the whole application just “feels” a bit wrong.

I’m at an early enough stage that if it needs to be changed significantly, it can be. I think I might be confusing different design patterns and then confusing myself into making poor decisions. I have provided a simplified version of the code below, which is identical to my own code, minus the Sharepoint stuff and some of the properties in some of the classes (just for readability).

Conversion abstract class

public abstract class Conversion     {         protected abstract IDocument Document { get; set; }         protected abstract bool SaveDocumentLocal { get; set; }         public Stream ConvertDocument()         {             BeforeConvert();             var conv = Convert();             if (SaveDocumentLocal)             {                 this.SaveLocally(conv);             }             return conv;         }          protected virtual void BeforeConvert() { }         protected virtual Stream Convert() { return new MemoryStream(); }         protected virtual void SaveLocally(Stream doc) { }     } 

IDocument interface

public interface IDocument         {         string Url { get; set; }         string LocalPath { get; set; }         int MinorVersion { get; }         int MajorVersion { get; }         DateTime CreateDate { get; set; }         void SetVersion(int minor, int major);         } 

Document class

public class Document : IDocument         {         public string Url { get; set; }         public string LocalPath { get; set; }         public int MinorVersion { get; private set; }         public int MajorVersion { get; private set; }         public DateTime CreateDate { get; set; }         public FileExtension Extension { get; set; }          public Document(string url)         {             Url = url;             CreateAndSetLocalPath();             SetFileName();             Extension = SetFileExtension();             SetVersion(2,0);         }         private FileExtension SetFileExtension() { return new FileExtension(); }         private void SetFileName() { Console.WriteLine("Set the filename"); }         private void CreateAndSetLocalPath() { Console.WriteLine("Created and set local path"); }         public void SetVersion(int major, int minor) { Console.WriteLine("Version set to {0}.{1}", major, minor); }         } 

WordDocumentConverter class

public class WordDocumentConverter : Conversion     {         public WordDocumentConverter(IDocument doc)         {             Document = doc;             //Construct object         }         protected override IDocument Document { get; set; }         protected override bool SaveDocumentLocal { get; set; }         protected override void BeforeConvert()         {             //Do stuff before converting         }         protected override Stream Convert()         {             //Specific Word document conversion logic here to convert the IDocument to something else             Console.WriteLine("Converted from Word to PDF");             return new MemoryStream();         }         protected override void SaveLocally(Stream doc)         {             //Specific save logic here...             Console.WriteLine("Saved a copy of 'doc' locally");         }     } 

Example calling code

var doc = new Document(@"C:\temp\doc1.docx"); var wdc = new WordDocumentConverter(doc); wdc.ConvertDocument(); 

Let me know if I’m missing anything or haven’t explained myself properly. Thanks.