Last post Jan 05, 2018 10:07 PM by DA924
Jan 03, 2018 02:37 PM|tridip1974|LINK
please tell me when to use observable design pattern in asp.net mvc and webform. i am looking for a good article on observable design pattern with asp.net mvc and webform.
please some one discuss it with a nice example. thanks
Jan 05, 2018 06:00 AM|DA924|LINK
The observer design pattern is yet another, one of my favorite design patterns which falls in the category of "behavioral pattern". Going by its name, we can say that observer is something (objects in case of OOPS) which is
looking upon (observing) other object(s). Observer pattern is popularly known to be based on "The Hollywood Principle" which says- "Don’t call us, we will call you."
Pub-Sub (Publisher-Subscriber) is yet another popular nickname given to Observer pattern.
Based on the "Hollywood principle", we can make a guess that in observer pattern, there is a special
Hollywood celebrity object in which all other common objects are interested. In actual terms in the observer pattern - "There are n numbers of
observers (objects) which are interested in a special object (called the subject).
Explaining one step further- there are various objects (called observers) which are interested in things going on with a special object (called the
subject). So they register (or subscribe) themselves to subject (also called
publisher). The observers are interested in happening of an event (this event usually happens in the boundary of
subject object) whenever this event is raised (by the subject/publisher) the observers are notified (they have subscribed for the happening of this event- Remember?)
Jan 05, 2018 11:22 AM|tridip1974|LINK
what is the scope for observable design pattern in asp.net webform or mvc.
can you please come with small and nice example. thanks
Jan 05, 2018 10:07 PM|DA924|LINK
You could use the pattern in the Model of a MVC solution, since it is the Model object that is supposed to have the business logic with controllers being thin., if not using n-tier. In this case Model objects could subscribe to a publisher Model object to
complete a task.
An MVC model contains all of your application logic that is not contained in a view or a controller. The model should contain all of your application business logic, validation logic, and database access logic.
In general, you should strive for fat models and skinny controllers. Your controller methods should contain only a few lines of code. If a controller action gets too fat, then you should consider moving the logic
out to a new class in the Models folder.
Web form solution would need to be using Model View Presenter with the presenter working with the domain/business objects using the pub/sub pattern.
You can implement the interaction with the model in several ways. For example, you can implement the Observer pattern. This means that the presenter receives events from the model and updates the view as required. Another approach is to use an application
controller to update the model.
You would see the pattern used in the Business logic layer with business object behavior.
You may see the pattern being used in the Repository layer with repository object behavior.
You may see the pattern being used in the Service layer with service object behavior.
All of the above would have objects subscribing to a publishing object in the particular layer to perform a task.
It's up to the architect/developer/you to determine when the pattern would be beneficial based on a given need.
You have seen examples of how the pub/sub is implemented and where, and again it's up to you to know when and how to implement the pattern.