I have an abstract Catalog class as follows. It has a static OpenCatalog () method, which is used to return a specific directory based on the type of location provided. After determining the type of directory, it calls the specific OpenCatalog () method for the specific type of the specific directory. For example, I may have a directory implementation that is stored in an SQL database or another that is stored in the file system. See code below.
public abstract class Catalog
{
public static ICatalog OpenCatalog(string location, bool openReadOnly)
{
if(location is filePath)
{
return FileSystemCatalog.OpenCatalog(string location, bool openReadOnly);
}
else if(location is SQL server)
{
return SqlCatalog.OpenCatalog(string location, bool openReadOnly);
}
else
{
throw new ArgumentException("Unknown catalog type","location");
}
}
...
}
public abstract class FileSystemCatalog:Catalog
{
public static new ICatalog OpenCatalog(string location, bool openReadOnly)
{
}
...
}
public abstract class SqlCatalog:Catalog
{
public static new ICatalog OpenCatalog(string location, bool openReadOnly)
{
}
...
}
First, is it okay to hide the static method? I know that this is possible, but it also looks like something that needs to be done not very often. Also, is this a valid example where you can hide a static method, or is there a better way to do what I'm trying to do?