开发者

Event pattern (.NET example requested)

开发者 https://www.devze.com 2023-01-26 20:25 出处:网络
Any help with building the following design around a .NET app would be appreciated. Imagine that we have different types of articles: lets say, NewsArticle, BlogArticle, EditorialArticle etc. They ar

Any help with building the following design around a .NET app would be appreciated.

Imagine that we have different types of articles: lets say, NewsArticle, BlogArticle, EditorialArticle etc. They are different in some ways, the same in others, thus they all inherit from an Article base class.

We want a nice modular design so that some of these Article types can be packaged up in seperate modules, or developers can build their own Article types.

When an article is published and becomes publicly visible, a whole series of services have to run - e.g. people need to be emailed, fields have to be updated in the database, etc.

This reminds me of the Observer/event pattern, but I'm not sure how we go about registering observers. What exactly is the subject in this case - is it the Article itself? Where should we register the events - in Global.asax or similar perhaps - this seems a bit strange to me? Am I going down the right track - what would the overall top-level architecture look lik开发者_运维问答e?


this is Observer pattern and you don't need to register events in Global.asax but register Observer classes in the Subject class of this DP.


If services have to run, then the observers are the services theirselves.


There is Exploring the Observer Design Pattern on MSDN which explain Observer Pattern and how to use this pattern with event in .NET (aka. Event Pattern)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号