I have a couple different custom backup programs and I want to combine them into a single one. Doing so, I'm working on my OO design to help keep the driving program simple and easy to follow by abstracting my server and database information.
I'm using two different hosts (Discount ASP.net and Rackspace). Both of them go about their backups in a slightly different manner.
I've tried looking into a few different approaches, but here is the route that I think makes most sense.
I have my base class:
public abstract class DBServer
{
public List<Database> Databases { get; set; }
public abstract bool MakeBackupCall(Database d);
}
and then two derived classes:
public class DASPServer : DBServer
{
public string APIKey { get; set; }
public override bool MakeBackupCall(Database d)
{
// do some stuff
return true;
}
}
public class RackspaceServer : DBServer
{
public override bool MakeBackupCall(Database d)
{
// do some different stuff
return true;
}
}
The problem comes in with my related object Database
.
Since the backup processes are different for each host, I require different information for the databases. For example, for Discount ASP.net I need a version (2000, 2005, 2008) for the database so I know which of their web services to call. For Rackspace, I need the external server name, database username and passwords to create a connection string. Because of this, I tried creating a database object with the following hierarchy.
public abstract class Database
{
public string Name { get; set; }
}
public class DASPDatabase : Database
{
public string Version { get; set; }
}
public class RackspaceDatabase : Database
{
public string ServerName { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
protected string ConnectionString
{
get { return string.Format("Data Source={0};Network Library=;Connection Timeout=30;Packet Size=4096;Integrated Security=no;Encrypt=no;Initial Catalog={1};User ID={2};Password={3}", ServerName, Name, UserName, Password); }
}
}
What I want to do, is ensure that my DASPServer instance always gets instances of DASPDatabases, and the same with Rackspace. Alternatively, I would like a smack in the head if I am going about this in the wrong direction.
Many thanks in advance