S
Soon
Hi,
I am new to C# and have a question regarding interface implementation in C#. In the COM days, we can have multiple COM objects implementing the same interface and instantiating one of them depending on the business requirements. For instance:
public function GetSavingAccountBalance(str_AcctNo as string, int_BankID as Integer) as double
Dim objSavingAcct as IBankAccount
if ( ID_BANK_1 = int_BankID ) then
set objSavingAcct = CreateObject ("Bank1.SavingAccount.1")
elseif ( ID_BANK_2 = int_BankID ) then
set objSavingAcct = CreateObject ("Bank2.SavingAccount.1")
end if
GetSavingAccountBalance = objSavingAcct.Balance( str_AcctNo )
set objSavingAcct = nothing
End Sub
In this case, both Bank1.SavingAccount.1 and Bank2.SavingAccount.1 are ProgIDs for 2 COM objects, and they both implement IBankAccount interface. If there are changes in the business logic, all I need to do is to instantiate another object with a different ProgID (which can be retrieved from a configuration file). This way I do not have to recompile the client again and makes the architecture very flexible.
How do I do this in C#? Any help will be appreciated. Thanks in advance.
Cheers,
Soon
I am new to C# and have a question regarding interface implementation in C#. In the COM days, we can have multiple COM objects implementing the same interface and instantiating one of them depending on the business requirements. For instance:
public function GetSavingAccountBalance(str_AcctNo as string, int_BankID as Integer) as double
Dim objSavingAcct as IBankAccount
if ( ID_BANK_1 = int_BankID ) then
set objSavingAcct = CreateObject ("Bank1.SavingAccount.1")
elseif ( ID_BANK_2 = int_BankID ) then
set objSavingAcct = CreateObject ("Bank2.SavingAccount.1")
end if
GetSavingAccountBalance = objSavingAcct.Balance( str_AcctNo )
set objSavingAcct = nothing
End Sub
In this case, both Bank1.SavingAccount.1 and Bank2.SavingAccount.1 are ProgIDs for 2 COM objects, and they both implement IBankAccount interface. If there are changes in the business logic, all I need to do is to instantiate another object with a different ProgID (which can be retrieved from a configuration file). This way I do not have to recompile the client again and makes the architecture very flexible.
How do I do this in C#? Any help will be appreciated. Thanks in advance.
Cheers,
Soon