Project Description
Adds multimethod support for .NET enabling fast polymorphic dispatch based on argument types.

MultiMethods.NET is developed in C# 3.0 and targets the 2.0 runtime.

Enables development of loosely coupled systems where class hierarchies and behavior evolve over time.

Example and Usage
Examples of multimethod usage generally discuss complex expression tree walking, shape intersection, or variations of visitor pattern.

But here is a real world example that hopefully illustrates the power of multimethods in business applications.
  • A payment processor needs to handle different payment types
    • Credit card, ACH etc
  • There are special billing rules/behavior applicable to certain payment types
    • A free trial period for all payments
    • BIN (bank identification number) suppression just for credit cards
Note that the behavior varies based on not only the payment type, but also the billing rule in effect

Here is the implementation based on multimethods.

Note that new payment types, billing rules and dynamic behavior can be added without changing the PaymentService interface.
Enjoy - and say bye bye to your hand crafted visitors :-)

Multimethods vs Visitor pattern
Wikipedia Multiple dispatch entry
Double dispatch from Modern C++ Design, Andrei Alexandrescu
Multiple Dispatch in Perl, Damian Conway
Making reflection fly and exploring delegates, Jon Skeet
My brute force dynamic IL based multimethod implementation for .NET 1.1 written back in '03

You need NUnit 2.5 to run the units tests accompanying the code

Last edited Feb 23, 2009 at 1:11 PM by ajaishankar, version 30