Observer Pattern

Tuesday, 18 March 2008 15:58 by Frimbob

I have been doing some reading on design patterns an in particular the Observer Pattern.

In short the pattern helps to de-couple code modules by providing a third party class that will acts as observers to concrete classes. These observes act as an intermediary to send messages from one class to another.

This avoids having to directly reference other classes using a full qualified name and thus creating a dependency.

I have found some documentation on MSDN on Implementing the observer pattern in .net.

It  appears that by using delegates and events offered by the .NET frame work that less code is required than I originally though necessary.

I might use this pattern in my OOP university project if I can get my Lecture to approve of C++/CLI over his much loved classic C++ .  

Links

[Implementing observer in .net]

http://msdn2.microsoft.com/en-us/library/ms998543.aspx

[Observer Pattern MSDN documentation]

http://msdn2.microsoft.com/en-us/library/ms978753.aspx

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Java-Script Widget Pattern

Saturday, 23 February 2008 17:55 by Frimbob

The Design pattern below for a JavaScript widget, is inspired by the pattern used for YUI-Framework widgets. I have made a copy for future projects. Some of the Features of this pattern are.

  • Constructor by calling object.init().
  • Public and Private Variables.
  • Public and Private Function.
  • Encapsulated in a namespace.

//repeat below line only once to create the Namspace

var NameSpace = function (){//empty add properties later}

//widget model.

NameSpace.Name = function()
    {
        // Private Variable for the module. Not accessible from outside 
        // Private function. Not accessible from outside 
    return { 
                  //public properties 
   return this; 
                //public functions

     init : function(){ // Priviledged method. Can be called from outside
            // Here comes the initialisation code }, //end int function 
      }; //end of return 
  }();  //end of module

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5