Function Delegation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have a project that we are developing in C# and one of our biggest requirements is that this be a single application but that many of the functions be customized depending on which cost center the user belongs to. In reality, what this typically means is that the user interfaces are the same everywhere but there are some business logic that is different from cost center to cost center. As much as possible we are building switches into the code from logic that we can anticipate, but we realize from experience (this is v3 of this product) that it just isn't possible to handle all business logic through switches and some custom code will be required. So, my question is what techniques have others found work in C# for accomplishing this goal? The "core" components cannot be modified, but it is acceptable to add new custom components to the application that might override some of the functionality of those "core" components.

I'm relatively new to C# (former VB6 programmer) and from what I've found so far, it appears that using delegates may be a promising technique. The one gotcha that I've run into so far is that I can't figure out how to get a reference to a component and function at runtime to use as the delegate. What I mean is that I would like my "core" function to lookup (in a database or session variable) the file name of an assembly which holds the delegate function and then call it in place of the compiled function code. So, pseudo-code might look like:

void CoreFunc()
{
// See if there is a cost center specific delegate
if( _costCenterAssemblyName != "" )
{
call GetDelegateFunc( _costCenterAssemblyName + ".CoreFunc()" );
return;
}
// Otherwise, do what you would normally do...
...
}

Any help with how to accomplish this or suggestions of a better method would be greatly appreciated.

Thanks!!!

Ian
 
Ian,
I would recommend the PlugIn Pattern coupled with the Seperated Interface
Pattern.

http://www.martinfowler.com/eaaCatalog/plugin.html
http://www.martinfowler.com/eaaCatalog/separatedInterface.html

For some thoughts on implementing the Plug In Pattern in C# see:
http://www.yoda.arachsys.com/csharp/plugin.html

Hope this helps
Jay

R. Ian Lee said:
We have a project that we are developing in C# and one of our biggest
requirements is that this be a single application but that many of the
functions be customized depending on which cost center the user belongs to.
In reality, what this typically means is that the user interfaces are the
same everywhere but there are some business logic that is different from
cost center to cost center. As much as possible we are building switches
into the code from logic that we can anticipate, but we realize from
experience (this is v3 of this product) that it just isn't possible to
handle all business logic through switches and some custom code will be
required. So, my question is what techniques have others found work in C#
for accomplishing this goal? The "core" components cannot be modified, but
it is acceptable to add new custom components to the application that might
override some of the functionality of those "core" components.
I'm relatively new to C# (former VB6 programmer) and from what I've found
so far, it appears that using delegates may be a promising technique. The
one gotcha that I've run into so far is that I can't figure out how to get a
reference to a component and function at runtime to use as the delegate.
What I mean is that I would like my "core" function to lookup (in a database
or session variable) the file name of an assembly which holds the delegate
function and then call it in place of the compiled function code. So,
pseudo-code might look like:
 
Hi,

I suggest you to look into the abstract factory pattern, using it you can
use a different set of components in an easy way. Usually the abstract
factory is implemented using the Singleton pattern so you may want to take a
look at it too.

See this link:
http://www.dofactory.com/Patterns/PatternAbstract.aspx

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

R. Ian Lee said:
We have a project that we are developing in C# and one of our biggest
requirements is that this be a single application but that many of the
functions be customized depending on which cost center the user belongs to.
In reality, what this typically means is that the user interfaces are the
same everywhere but there are some business logic that is different from
cost center to cost center. As much as possible we are building switches
into the code from logic that we can anticipate, but we realize from
experience (this is v3 of this product) that it just isn't possible to
handle all business logic through switches and some custom code will be
required. So, my question is what techniques have others found work in C#
for accomplishing this goal? The "core" components cannot be modified, but
it is acceptable to add new custom components to the application that might
override some of the functionality of those "core" components.
I'm relatively new to C# (former VB6 programmer) and from what I've found
so far, it appears that using delegates may be a promising technique. The
one gotcha that I've run into so far is that I can't figure out how to get a
reference to a component and function at runtime to use as the delegate.
What I mean is that I would like my "core" function to lookup (in a database
or session variable) the file name of an assembly which holds the delegate
function and then call it in place of the compiled function code. So,
pseudo-code might look like:
 
OK, so now that I understand how to make a plug-in work there's now the question of security. What is the best way that my program can ensure that "plugin" assemblies are properly signed? Is there a global way or do I have to do this with every Reflection call

Thanks

Ian
 
Back
Top