Search This Blog

Showing posts with label Design patterns. Show all posts
Showing posts with label Design patterns. Show all posts

Saturday, June 29, 2013

Observer Design Pattern

         Definition in Wikipedia:
"The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems. The Observer pattern is also a key part in the familiar Model View Controller (MVC) architectural pattern. In fact the observer pattern was first implemented in Smalltalk's MVC based user interface framework. The observer pattern is implemented in numerous programming libraries and systems, including almost all GUI toolkits."
          In www.dofactory.com the Observer Design Pattern is the  this:
          

In terms of the .NET Framework the terminology is a bit difference:
The abstract class Observer is replaced by the IObserver  interface.
The  abstract class Subject is replaced by the IObservable  interface.
The class ConcreteSubject usually is called Observable.
The function Attach is replaced by the function Register.
The function Dettach is replaced by the function Unregister
Also under the term  container we mean some generic type collection in which we can have the observers.

Monday, June 24, 2013

Wrapper class




/// Example for Wrapper class
Structural design patterns 
Proxy, Decorator, and Adapter also use thiw approach.
see more...


public class WrapperExample
{
    private int x = 20;
    private int y = 10;

   
    public WrapperExample()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public int mul(int x, int y)
    {
        Wrapper.internalClass obj = new internalClass();
        //core functionality of this method is written in the wrapped class.
        int res = obj.mul(x, y);
        return sum;
    }

    ///
    /// this class is wrapped by the WrapperExample class.
    /// we can access only inside this class.
    /// outside the class, we cant access this class.
    ///
    private class internalClass
    {       

        public int mul(int x, int y)
        {
          
            return x * y;
        }
    }
}
 

IHttpHandlerFactory and Abstarct Factory Design Pattern

http://www.dofactory.com/Patterns/PatternAbstract.aspx


In terms of Abstract Factory design pattern, the IHTTPHandlerFactory forms the abstract factory,
the IHTTPHandler forms the abstract product, the PageHandlerFactory forms the concrete factory and the Page class forms the concrete Product. 

IHTTPHandlerFactory<->Abstract Factory
IHTTPHandler<->abstract produc
pagehandlerfactory<->concrete factory (1 or more)
Page Class<->concrete Product.  (1 or more)

Friday, June 21, 2013

MVVM,MVP,MVC




ASP.NET MVC

ASP.NET is a development framework for building web pages and web sites with HTML, CSS, JavaScript and server scripting.
ASP.NET supports three different development models:
Web Pages, MVC (Model View Controller), and Web Forms.

Web Forms vs MVC

The MVC programming model is a lighter alternative to traditional ASP.NET (Web Forms). It is a lightweight, highly testable framework, integrated with all existing ASP.NET features, such as Master Pages, Security, and Authentication.

Introduction

MVC
....
ASP.NET MVC

Tuesday, June 18, 2013

Combose Design Patterns

I think that the following article is one of the more interesting articles I ever seen!!

<<


In this new field of software engineering, the following

important questions are arising:

• Amongst the many different design patterns

that are being discovered, are any related to

each other? What are the characteristics of

such a relationship?

• Do two patterns address a similar problem

area?
 
Is it possible to combine two design patterns?

• What are the criteria for classifying design

patterns into categories?
 
>>

Dessign Patterns Collaboration (.pdf)

Intercepting Filter design pattern

The simplest form of this pattern is the following:

switch (condition){
     case Value1:

      case Value2:

     default:
}

Another approach to Intercepting Filter Pattern
Once a request has made it into an HttpApplication, it passes through any number of IHttpModules. Each module is independent and has only a limited amount of control over the order in which it is invoked. The HttpApplication class exposes a sequence of events that get raised as the request makes its way through processing. These events include BeginRequest, AuthenticateRequest, AuthorizeRequest, and EndRequest. When the HttpApplication loads a module, it calls the Init method of the IHttpModule interface, allowing the module to register for any of the events it cares about. As a given request is handled, the events are raised in the appropriate order and all registered modules get a chance to interact with the request. The module can therefore control the stage at which it gets invoked, but not the exact order within that stage.
These modules are an example of the Intercepting Filter pattern. This pattern represents a chain of filters that are each in turn given a chance to modify a request (or message) that passes through them. Figure  shows a simplified flow diagram of this process. The key ideas of this pattern are that the filters are independent; filters can modify the request as it passes through.
 

Figure  Request Flow  
 
There are several different implementation variations of the Intercepting Filter pattern, one of which is the event-based model employed by ASP.NET. A simpler variant involves maintaining a list of filters and iterating over it, invoking a method on each one in turn. This is how the Web Services Enhancements (WSE) for ASP.NET Web services uses this pattern. Each filter either extends SoapInputFilter (for request messages) or SoapOutputFilter (for responses), overriding the ProcessMessage method to perform the work of the filter.
Another option is to implement Intercepting Filter via the Decorator pattern. Then each filter would wrap its successor, performing preprocessing, invoking the successor, and then performing post-processing. The chain would be built using recursive composition, from back to front. This pattern is used to implement .NET Remoting channel sinks.
Regardless of implementation, the result is a dynamically configurable chain of independent filters. Since they are independent, these filters can easily be reordered and reused in other applications. Common tasks like authentication or logging can be encapsulated in a filter and used over and over. These tasks can then be handled by the filter chain before a request even reaches the HttpHandler, keeping the handler code cleaner.


Decorator Dessign Pattern
see also:Intercepting filter in java

Chain of Responsibility

The simplest form of this pattern is the following:


try{


   }catch(Exception ex){

   }
   finally{

   }

After the try block the responsibility will be passed down only 
to the finally or to both  Catch and Finally blocks depending on the errors -if there are some of them.!!

http://www.dofactory.com/Patterns/PatternChain.aspx

See also Loose_coupling

Sunday, June 16, 2013

Categories og desifn patterns

  Creational Patterns
 Patterns for dynamically selecting the class of created objects.
  Abstract Factory  Creates an instance of several families of classes
  Builder  Separates object construction from its representation
  Factory Method  Creates an instance of several derived classes
  Prototype  A fully initialized instance to be copied or cloned
  Singleton  A class of which only a single instance can exist

  Structural Patterns
Category of patterns that use various language mechanisms for structuring code and assembling objects.
  Adapter  Match interfaces of different classes
  Bridge  Separates an object’s interface from its implementation
  Composite  A tree structure of simple and composite objects
  Decorator  Add responsibilities to objects dynamically
  Facade  A single class that represents an entire subsystem
  Flyweight  A fine-grained instance used for efficient sharing
  Proxy  An object representing another object

  Behavioral PatternsBehavioral patterns based on class tend to use inheritance to describe algorithms and flow of control, whereas the Behavioral patterns that target objects usually describe how a group of objects collaborate to perform some task that no single object can perform alone.
  Chain of Resp.  A way of passing a request between a chain of objects
  Command  Encapsulate a command request as an object
  Interpreter  A way to include language elements in a program
  Iterator  Sequentially access the elements of a collection
  Mediator  Defines simplified communication between classes
  Memento  Capture and restore an object's internal state
  Observer  A way of notifying change to a number of classes
  State  Alter an object's behavior when its state changes
  Strategy  Encapsulates an algorithm inside a class
  Template Method  Defer the exact steps of an algorithm to a subclass
  Visitor  Defines a new operation to a class without change

Design Patterns For-Beginners

<
For example, let's take a lot of Resumes submitted for a job vacancy. Everybody's resume doesn't look the same... although they all tend to do the same thing, that is telling a reader what they are skilled at, or how he/she can be a fit for the job.
Majority of them who submit resumes to jobs, know that they need to submit a resume with a particular set of information in a formatted Word document.
This... is a pattern, that everybody submits a resume with a particular set of information expressed in it.>>

Design Patterns For-Beginners

Provider Model Design Pattern

The beauty of this pattern is you can create a new class, for example, OracleForumsProvider, by deriving from the ForumsProvider base class and use Oracle as your data store. Or, if you prefer to continue using SQL Server, but wish to change the behavior of a single method, you can derive from SqlForumsProvider, override the method whose behavior you want to change, and then add that new class to the section of configuration. More simply put: the provider design allows developers to publish well-known APIs and also allows for a rich, enterprise-level extensibility model.


It is not a brand new idea; it came basically from the popular strategy pattern. It is a good idea to have a quick look at the strategy pattern in here.



MSDN
Provider-Pattern
http://www.codeproject.com/
strategy design pattern

About Me

An seasoned developer, architect and with some Team Leading exposure, offering full project life cycle experiences within multi cultural, multi National environments and within differing business streams and all primarily on a .Net platform.