Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace FactoryMethod
- {
- public interface IConnectionProvider
- {
- string ConnectionString { get; }
- }
- public class SqlServerConnection : IConnectionProvider
- {
- public string ConnectionString
- {
- get { return "Server=(local);initial catalog=AdventureWorks;Integrated Security=SSPI"; }
- }
- }
- public class OracleConnection : IConnectionProvider
- {
- public string ConnectionString
- {
- get { return "User ID=vorleak;Password=vorleak;Data Source=localhost"; }
- }
- }
- public class MySqlConnection : IConnectionProvider
- {
- public string ConnectionString
- {
- get { return "Database=AdventureWorks;Data Source=192.168.0.1;User Id=vorleak;Password=vorleak"; }
- }
- }
- public class ConnectionProviderFactory
- {
- public IConnectionProvider CreateConnection(string type)
- {
- switch (type)
- {
- case "SQL Server" :
- return new SqlServerConnection();
- case "Oracle" :
- return new OracleConnection();
- case "MySQL":
- return new MySqlConnection();
- default:
- return null;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment