Saturday, 15 May 2010

c# - how to declare variable on 2 class -


I have 2 classes that try to connect to mysql

These 2 classes Does not have the same method as

  if (isRemote) {RemoteMySQL mySql = new RemoteMySQL (); } Other {MySQL mySQL = New MySQL (); } MySql.Connect ();  

When i mySQL like this mySql.Connect (); declares the error does not come out in the current context.

I will use the factory design pattern in your case. Code should be ...

  Public interface IMISCall {zero connect (); } Class Remote My SQL: Imi SQL {Public Zero Connect () {}} Category MySQL: IMySql {Public Zero Connect () {}}  

in Factory.cs,

When you want to consume the factory, you can use the code like this:

  var mysql = factory (true); // remote Sms mysql.connect ()  

No comments:

Post a Comment