Skip to main content

Posts

Showing posts with the label Design Pattern

Revealing Module Pattern in JavaScript

Revealing Module Pattern makes the code to read better and more structured way, This really useful when we had to repeat the name of the main object when we wanted to call one public method from another or access public variables. This is done by adding a return statement at the end of the function that exposes the public members. The benefits of this approach are. The Revealing Module Pattern allows the syntax of your script to be fairly consistent - it also makes it very clear at the end which of our functions and variables may be accessed publicly, something that is quite useful. In addition, we also able to reveal private functions with more specific names if we wish. The following code demonstrates how the module can be revealed. var myModule = (function () { var name = 'Mohamed Rafeeq'; var age = 28; function updatePerson() { name = 'Mohamed Rafeeq Updated'; } function setPerson() { name = 'Mohamed Rafeeq Set...

Observer Pattern With C# 4.0

Observer Pattern "The Observer Pattern Defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically." Publishers + Subscribers = Observer Pattern C# Introduced , IObserver<T> and IObservable<T> which will help push-based notification,also known as the observer design pattern. The IObservable<T> interface represents the class that sends notifications (the provider); the IObserver<T> interface represents the class that receives them (the observer). T represents the class that provides the notification information. An IObserver<T> implementation arranges to receive notifications from a provider (an IObservable<T> implementation) by passing an instance of itself to the provider's IObservable<T>.Subscribe method. This method returns an IDisposable object that can be used to unsubscribe the observer before the provider finishes sending...