Two classes, the same methods, one object?

I am working on a C # project using Oracle Siebel CRM. Siebel provides two spaces and classes that are used to connect to them programmatically, depending on whether you want to connect to a server or connect to a client session:

SiebelBusObjectInterfaces.SiebelDataControl
TWSiebelLib.SiebelWebApplication

SiebelDataControl provides a specific method for explicitly logging on to a server resource:

bool SiebelDataControl.Login(string connString, string userName, string passWord)

All other methods are identical between the two classes.

I currently support two versions of my application - one for each of the individual connection classes. As the functionality that I create becomes more and more comprehensive and complex, it becomes a real struggle to keep both applications separate. I split the piece of connectivity into my class, but I still have to copy and paste the code between the applications as it develops.

Ideally, I want a single VS solution that has one instance of all my code, and some logic that determines which of the two connection classes to use, be decided by the user.

Theoretically, I want something like:

class SiebelAppWrapper {

    public Object m_SiebelAppInstance;
    private Boolean m_isConnected;
    private short m_conType;

    public static short SERVER_CON = 1;
    public static short CLIENT_CON = 2;

    public SiebelAppWrapper(short conType) {
        if (conType == SERVER_CON) {
            m_SiebelAppInstance = new SiebelDataControl();
          } else if conType == CLIENT_CON {
            m_SiebelAppInstance = new SiebelWebApplication();
        } 
        m_conType = conType;
    }
}

But, for obvious reasons, the compiler is not satisfied with this.

I'm new to C # and .NET development in general, so I hope there is a way for me to include both classes without replicating all the dependency code.

.

+4
2

:

  • ISiebelWhatever, , .
  • : ISiebelWhatever.
  • ISiebelWhatever m_SiebelAppInstance.

, , sealed, , . , , : , ? , , ? .

, , , ( ISiebelWhatever) .

+11

, ?

+3

Source: https://habr.com/ru/post/1534617/


All Articles