Archive for the ‘General’ Category

Abstract Factory Design Pattern C# .NET

Abstract Factory in the .NET Framework

ADO.NET 2.0 includes two new Abstract Factory classes that offer provider independent data access techniques.

They are: DbProviderFactory and DbProviderFactories. The DbProviderFactory class creates the ‘true’ (i.e. the database specific) classes you need, such as SqlClientConnection, SqlClientCommand, and SqlClientDataAdapter.

Each managed provider (such as SqlClient, OleDb, ODBC, and Oracle) has its own DbProviderFactory class. DbProviderFactory objects are created by the DbProviderFactories class, which itself is a factory class. In fact, it is a factory of factories — it manufactures different factories, one for each provider.

When Microsoft talks about Abstract Factories they mean types that expose factory methods as virtual or abstract instance functions and return an abstract class or interface.

Definition :

Provide an interface for creating families of related or dependent objects without specifying their concrete classes

Participants:

The classes and/or objects participating in this pattern are:
AbstractFactory (ManufacturerFactory)
 

declares an interface for operations that create abstract products

ConcreteFactory (AppleFactory, NokiaFactory)
 

implements the operations to create concrete product objects

AbstractProduct (3G, 2G)
 

declares an interface for a type of product object

Product (iPhone 2G/3G, N81, N95)
 

defines a product object to be created by the corresponding concrete factory implements the AbstractProduct interface

Client (PhoneWorld)
 

uses interfaces declared by AbstractFactory and AbstractProduct classes

 

 

UML Diagram:

Abstract Factory Design Patter

using System;
 
namespace Osman.Abstract
{
 
    /// <summary></summary>
    /// The 'AbstractFactory' interface.
    /// 
    interface IManufacturerFactory
    {
        I3G Create3GPhone();
        I2G Create2GPhone();
    }
 
    /// <summary></summary>
    /// The 'ConcreteFactory1' class.
    /// 
    class AppleFactory : IManufacturerFactory
    {
 
        #region IManufacturerFactory Members
 
        public I3G Create3GPhone()
        {
            return new iPhone3G();
        }
 
        public I2G Create2GPhone()
        {
            return new iPhone2G();
        }
 
        #endregion
    }
 
    /// <summary></summary>
    /// The 'ConcreteFactory2' class.
    /// 
    class NokiaFactory : IManufacturerFactory
    {
 
        #region IManufacturerFactory Members
 
        public I3G Create3GPhone()
        {
            return new N95();
        }
 
        public I2G Create2GPhone()
        {
            return new N81();
        }
 
        #endregion
    }
 
    /// <summary></summary>
    /// &quot;AbstractProductA&quot;
    /// 
    interface I2G
    {
        void Support2G();
    }
 
    /// <summary></summary>
    /// &quot;AbstractProductB&quot;
    /// 
    interface I3G
    {
        void Support3G();
    }
 
    /// <summary></summary>
    /// The &quot;ProductA1&quot; class
    /// 
    class iPhone2G : I2G
    {
        #region I2G Members
 
        public void Support2G()
        {
            // Support 2G
            Console.WriteLine(this.GetType().Name + &quot; supports 2G&quot;);
        }
 
        #endregion
    }
 
    /// <summary></summary>
    /// The &quot;ProductB1&quot; class
    /// 
    class iPhone3G : I3G
    {
 
        #region I3G Members
 
        public void Support3G()
        {
            // Support 3G
            Console.WriteLine(this.GetType().Name + &quot; supports 3G&quot;);
        }
 
        #endregion
    }
 
    /// <summary></summary>
    /// The &quot;ProductA2&quot; class
    /// 
    class N81 : I2G
    {
        #region I2G Members
 
        public void Support2G()
        {
            // Support 2G
            Console.WriteLine(this.GetType().Name + &quot; supports 2G&quot;);
        }
 
        #endregion
    }
 
    /// <summary></summary>
    /// The &quot;ProductB2&quot; class
    /// 
    class N95 : I3G
    {
 
        #region I3G Members
 
        public void Support3G()
        {
            // Support 3G
            Console.WriteLine(this.GetType().Name + &quot; supports 3G&quot;);
        }
 
        #endregion
    }
 
    /// <summary></summary>
    /// The 'Client' class (according to pattern UML).
    /// 
    class PhoneWorld
    {
        private I3G obj3GPhone;
        private I2G obj2GPhone;
 
        /// <summary></summary>
        /// Contructor of PhoneWorld
        /// 
        /// <param name="manufacturer" />Manufacturer of the phone world that is created.
        public PhoneWorld(Manufacturer manufacturer)
        {
            // Get fully qualified factory name
            string name = this.GetType().Namespace + &quot;.&quot; +
                manufacturer.ToString() + &quot;Factory&quot;;
 
            // Dynamic factory creation
            IManufacturerFactory factory =
                (IManufacturerFactory)System.Activator.CreateInstance
                (Type.GetType(name));
            obj3GPhone = factory.Create3GPhone();
            obj2GPhone = factory.Create2GPhone();
        }
 
        /// <summary></summary>
        /// Runs the SupportChain in the Phone world.
        /// 
        public void SupportChain()
        {
            obj3GPhone.Support3G();
            obj2GPhone.Support2G();
        }
    }
 
    /// <summary></summary>
    /// Enumeration of Phone Manufacturer.
    /// 
    public enum Manufacturer
    {
        /// <summary></summary>
        /// Represents Apple.
        /// 
        Apple,
 
        /// <summary></summary>
        /// Represents Nokia.
        /// 
        Nokia
    }
}

Main Class

   /// <summary></summary>
    /// Abstract Factory Design Pattern.
    /// 
    class MainEntry
    {
        /// <summary></summary>
        /// Entry point into console application.
        /// 
        public static void Main()
        {
            // Create and run the Apple phone world
            PhoneWorld objPhoneWorld = new PhoneWorld(Manufacturer.Apple);
            objPhoneWorld.SupportChain();
 
            // Create and run the Nokia phone world
            objPhoneWorld = new PhoneWorld(Manufacturer.Nokia);
            objPhoneWorld.SupportChain();
 
            // Wait for user input
            Console.Read();
        }
    }

 

Popularity: 2% [?]

Share

Online Professional Diagrams

Lovely Charts is an online diagramming application, that allows you to create professional looking diagrams of all kinds, such as flowcharts, sitemaps,organisation charts,wireframes, and many more… For Freeeeee

With Lovely Charts’s extremely simple and intuitive drag’n drop drawing mechanism, you’ll be able to focus on what really matters. You won’t have to draw boxes and arrows, you won’t have to worry about what symbol to use.
Check out our screencast to discover how it works, we’re pretty confident you’ll like what you’ll see.

http://www.lovelycharts.com/

Popularity: 2% [?]

Share

JavaScript Charts

http://www.jscharts.com/home

What is JS Charts?

JS Charts is a free JavaScript based chart generator that requires little or no coding. With JS Charts drawing charts is a simple and easy task, since you only have to use client-side scripting (i.e. performed by your web browser). No additional plugins or server modules are required. Just include our scripts, prepare your chart data in XML or JavaScript Array and your chart is ready!

JS Charts lets you create charts in different templates like bar charts, pie charts or simple line graphs.

 


view more examples…

Our online editor, that has an easy to use interface, enables you to create highly customized charts in minutes, and then export them (upload the sources to your server) or get the embedding code (hosted version).

Features. Why should you use JS Charts?

  • You don’t have to write code
  • It’s easy to integrate
  • It’s customizable
  • You can edit your charts online
  • You can create the three most common types of charts: bar, pie and line
  • Optionally, we host your charts on our servers
  • You can save your charts to your user account
  • It’s compatible with most web browsers
  • You don’t need any server-side plugins/modules.
  • It’s a 100% JavaScript component
  • It’s free to use and watermark-free.

 

Compatibility

Windows

  • Firefox 1.5 +
  • Internet Explorer 7
  • Internet Explorer 6
  • Safari 3.1 +
  • Opera 9 +
  • and other browsers

Mac

  • Firefox 1.5+
  • iPhone 1+
  • Safari 2+

Popularity: 2% [?]

Share

.NET Shout Out

2-5-2009 10-40-50 AM

Kazi Manzur Rashid has recently launched a new Community Site for .NET developers http://dotnetshoutout.com

It’s a categorized, hand picked index of .NET info, which is cool enough, but there is a really interesting aspect.

1.) It’s an ASP.NET MVC application

2.) It’s based on an Open Source CodePlex.com project  KiGG (http://codplex.com/KiGG).  KiGG was the first starter kit for ASP.NET MVC.

Check it out!

Popularity: 3% [?]

Share

Thank CBS 60 Minutes for Exposing Israeli Apartheid

During Israel’s war on Gaza we launched a campaign to end the media blackout and that journalists expose Israel’s crimes and apartheid. Thousands of supporters used our website to contact the presidents of big Media calling for better coverage. The campaign got their attention and some journalist have positively responded to our collective pressure.

On Sunday, January 25, CBS 60 Minutes aired an amazing segment exposing Israel’s apartheid against Palestinians.  The piece is by Senior CBS Foreign Correspondent Bob Simon, who is Jewish living outside Tel-Aviv and produced by Robert G, Anderson.

TAKE ACTION:

1. Watch this video

2. Send a thank you note to 60 Minutes, Bob Simon and Robert Anderson, using the below form

3. Urge & Invite everyone you know to watch the video and send a thank you note

 

http://action.gazajustice.org/t/4436/campaign.jsp?campaign_KEY=963

Popularity: 4% [?]

Share

Anti-Muslim Bombay Riot Expose

Policemen turned rioters during the 1992-1993 Anti-Muslim Bombay riots and politicians provoked communal/religious hatred—a CNN INDIA investigation proved on August 25, 2007.
 
 But will the guilty policemen and politicians will ever be brought to justice? Will the Justice Srikrishna report on the riots be implemented? A special debate finds out.
 
YouTube Preview Image
YouTube Preview Image
YouTube Preview Image
YouTube Preview Image
YouTube Preview Image
YouTube Preview Image
YouTube Preview Image
 

Popularity: 6% [?]

Share

HTTP Debugging Proxy

FiddlerLogo 

I’ve long been a Fiddler fan. It’s been a super valuable tool for debugging Javascript, WCF SOAP request and REST based code.

http://www.fiddlertool.com/

Firebug.

It rocks, but I think Firebug, A Web Development Must-Have,a free, open source extension for the Firefox browser that provides many useful developer features and tools. Using Firebug, you can monitor, edit, and debug live pages, including HTML, CSS, JavaScript code, and network traffic. One of the Best tool for debugging and tuning your Web and Ajax applications.

Popularity: 5% [?]

Share

TOOL: ePassport Photo

So why is it when we apply for visa or need a passport photo we rely on these shops which give us 2 photos for ~15-20 USD  per shot? And often when you have one of these photos you look like a joker.

Next time when you want to get your photos for Passport, Visa, Immigration … Wait… Dont waste your money at these places.

Here’s another interesting online tool: ePassport Photo.

Go to their site, upload your photo (follow the instructions), rotate and crop, download and print. Nifty!
 

Popularity: 7% [?]

Share

Intellisense for jQuery

I love jQeury. I’m a jQuery Fan !

Look at this example from the jQuery home page:


$("p.surprise").addClass("ohmy").show("slow");

That will get all the p elements with the class surprise, add the class “ohmy”, and then change the display to “block” with a slow animation. Go run it on the jQuery homepage.  Nice, eh?  The dollar function is magical.  You just give it a CSS selector, and it returns jQuery objects that you can do all kinds of cool things with.  Also, almost all the functions in the framework return this same jQuery object, so they are chainable like you see above.

Lance Fisher has made an update to jQuery for Intellisense in Visual Studio 2008

[ Click here to read about it and download jQuery with the Intellisense updates. ]

Popularity: 5% [?]

Share

What are Design Patterns?

I’m sure most of the good programmer like me probably don’t write any code until we build a picture in our mind of what the code does and how the pieces of the code interact.The more that you can picture this,  the more likely you are to feel comfortable that you have developed the best solution to the problem. If you don’t get this right away, you may keep staring out the window for a time if you are lucky to have a nice view from your office and if not then you may be staring at your desktop, even though the basic solution to the problem is quite obvious.

I feel that it’s very important for any programmer to develop a best elegant solution. The more elegant solution it is the more reusable it will be. That is why it is very important to satisfy this need for elegant, but simple, reusable solutions. That’s where the term "design patterns" comes in picture. It may sound very formal when you first encounter it but, in fact, design patterns are just convenient ways of reusing object oriented code between projects and between programmers.The idea behind design patterns is simple—write down and catalog common interactions between objects that programmers have frequently found useful.

Some useful definitions of design patterns

“Design patterns are recurring solutions to design problems you see over and over.” (The Smalltalk Companion)

“Design patterns constitute a set of rules describing how to accomplish certain tasks in the realm of software development.” (Pree 1994)

“Design patterns focus more on reuse of recurring architectural design themes, while frameworks focus on detailed design and implementation.” (Coplien and Schmidt 1995)

“A pattern addresses a recurring design problem that arises in specific design situations and presents a solution to it.” (Buschmann et al.1996)

“Patterns identify and specify abstractions that are above the level of single classes and instances, or of components.” (Gamma et al., 1993)

In next coming blogs, I will be discussing around 20 design patterns divided into three types: creational,structural, and behavioral.

Creational patterns create objects for you rather than having you instantiate objects directly. This gives your program more flexibility in deciding which objects need to be created for a given case.

Structural patterns help you compose groups of objects into larger structures, such as complex user interfaces or accounting data.

Behavioral patterns help you define the communication between  objects in your system and how the flow is controlled in a complex program.

We’ll be looking at C# versions of these patterns.

Popularity: 3% [?]

Share