I’m on a ASP.Net MVC project with LinqToSQL and multilayer. Users cand upload files, basically Excel and Access file and my service layer will do all of its validation and other stuff.
I was thinking about implement an abstract class named “UploadManager” and 2 child classes: “UploadExcel” and “UploadAccess”. Some methods will be common to both classes, such as “SaveFile” and “DeleteFile”. But, some other methods will be restricted to an especific child class, such as “ValidateWorksheet” that will belong to “UploadExcel” class only.
I was designing something like this:
public abstract class UploadManager
{
protected void SaveFile(string fileName)
{
//Implement
}
protected void DeleteFile(string fileName)
{
//Implement
}
}
public class UploadExcel : UploadManager
{
private bool ValidateWorksheet()
{
//Implement
}
}
public class UploadAccess : UploadManager
{
private bool ValidateSomethingAboutAccess()
{
//Implement
}
}
I was thinking about using Interfaces too. But, my main doubt is how can I know which child class I have to instantiate? If uploaded file is an Excel file, it will be “new UploadExcel()” and if it is an Access file, it will be “new UploadAccess()“.
Is there a way to accomplish this? Is there a better way? I’m some kinda lost with this…
Thanks in advance!!
The basic idea would be to inplement the validate method as
abstractin the base class.You then only have to worry about the child class when instantiating, for the rest you only deal with the base class methods:
And your classes would look more like