views:

63

answers:

1

I want to create a "modules" layout in my web application so I can easily add more modules of the same type, for example:

As an example, my WebApp handles subscriptions and email campaigns, and I want to create an interface to allow easily coupling multiple API's, MailChimp, CampaignMonitor, iContact, etc...

so I will create an IMailingService interface where I set up the ground rules and all modules will implement it like

public class CampaignMonitorService : IMailingService

So far so good...

How about fire the interface method upon an action on my webapp?

Should I implement the Observer Design Pattern, should I simple create event handlers, or any other hook?

for example, upon a user subscription I would like to fire the AddSubscriber method on the interface

AddSubscriber(string email, string[] args);

some thing as creating a list, unsubscribing, etc, etc...

What would be the best approach to handle such scenario?

+6  A: 

Event handlers are how the Observer pattern is normally implemented in .NET. The pattern is a first class citizen of the .NET world, very much like how the Iterator pattern is built in (with foreach and yield return).

If you do want to use the pattern without events/event handlers, you can use the new IObserver<T> and IObservable<T> (introduced in .NET 4.0).

Oded
I believe those were added in 3.5? +1 anyway.
Zor
@Zor - if you look at the documentation, you will see there is no entry for these for 3.5
Oded
`IObservable<T>` is only available in .NET Framework 4, but thank you for the heads up, I will make use of event handling for this.
balexandre
@balexandre - yes, it is new in .NET 4.0, as I noted in my answer.
Oded
I was getting at: http://msdn.microsoft.com/en-us/library/dd783449%28VS.90%29.aspx
Zor
@Zor - that's for phone/mobile only, not the desktop edition.
Oded