Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand

Archive for December, 2011

Windows Azure – AppFabric Access Control Service Portal

Posted by JP on December 31, 2011

As part of the Access Control Service, we are performing the following in this article.

  • Create new Namespace
  • Using the Access Control Service Portal
  • Create new Identity Provider
  • Create new Rule Group

Creating the Namespace

For creating the namespace, sign in to the Windows Azure Management Portal. Open the Service Bus, Access Control & Caching item as shown below. (You can also use the previous namespace if it exists)

clip_image002

In the appearing window select the Access Control item from the left pane.

clip_image004

In the appearing dialog enter the required details. Please ensure the namespace is unique.

clip_image006

After entering the details click on the Create Namespace button to create the namespace. Wait for a few minutes and you will be ready with the new namespace Active as shown below.

clip_image008

The namespace accesscontrol2011 can be used in our next Access Control article involving programming.

Using the Access Control Service Portal

You can open the Access Control Service Portal by selecting the namespace and clicking on the Access Control Service button from the header panel as shown below.

clip_image010

(You can also access it using the url https://namespace.accesscontrol.windows.net)

On clicking the button we will get the window shown below:

clip_image012

We can configure the Identity Providers using the link on left. There is a default created Windows Live ID item inside it.

clip_image014

Create new Identity Provider

Now we can add a new identity provider Google. Click on the Add button to continue. The following page appears.

clip_image016

Select the option Google and click Next to continue.

clip_image018

Leave the default options and click Save to create the provider.

We can configure the Relying party applications using the link on left. There are no default entries inside it.

clip_image020

Now you can see the new identity provider in the list as shown below.

clip_image022

Create new Rule Group

Now we have to create a new rule group for our application. At least one rule group is needed for getting valid token from ACS.

Click on the Rule Groups item from the left pane and you will see the following screen.

clip_image024

Click on the Add button from the above screen.

clip_image026

In the above screen enter a name for the rule group and click the Save button and you will be getting the following screen.

clip_image028

Click on the Generate button to generate the rules automatically. The following screen will appear.

clip_image030

Select (check) the items Google and Windows Live ID and click the Generate button. You will get the following screen.

clip_image032

Check all the items as shown above and click the Save button. Your rule group will be created in the list as shown below.

Summary

In this article we have seen creation of namespace, adding identity providers and rule groups using the Access Control Service Portal. In the next article we can create a web role and test the providers.

Advertisements

Posted in C# | Tagged: , , , | Leave a Comment »

Mediator Pattern

Posted by JP on December 27, 2011

In this article I would like to take you through the advantage of using Mediator Pattern. As always, Design Patterns if properly used gives us more flexibility and manageability. Mediator Pattern is of no deviation from this property.

Challenge

You are working on an Airline application managing flight validations. As you might know before taking off the flight, it goes through a series of checks ensuring the health of each component, the fuel level etc.

Our Flight class contains the following component classes

  • Engine
  • Wheels
  • Cockpit
  • Aviation

Each of the component class will be having a method named Start(). On invoking the method, it will ensure that the current state of component is valid through a method named IsReady(). If the IsReady() method returned true, the component class checks the other component IsReady() method. For example the Engine class ensures the Wheels and Aviation is in valid statue by using the IsReady() method of Wheel and Aviation respectively. The Cockpit in turn checks itself, Engine and the Aviation status. So there exists a coupling between the classes and code duplications. The scenario will become worse on introducing new components as classes.

clip_image002

How to make the code better?

Definition

Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.

Implementation

We can improve the above situation by introducing the Mediator pattern. Through the introduction of Mediator the component classes won’t talk to each other. All the components communicate to a new Mediator class. The advantages are:

  • Loosely coupled components
  • Centralized Management
  • More Flexibility in changing code

The new approach will look like below:

clip_image004

Here the component parts will communicate with the Mediator class for providing the ready signal to proceed with.

Classes

Following are the classes associated with the new implementation using Mediator Pattern.

public class FlightMediator

{

private Engine _engine;

private Aviation _aviation;

private Wheels _wheels;

private Cockpit _cockpit;

public FlightMediator(Engine engine, Aviation aviation, Wheels wheels, Cockpit cockpit)

{

_engine = engine;

_aviation = aviation;

_wheels = wheels;

_cockpit = cockpit;

}

public bool IsReady()

{

return _engine.IsReady() && _aviation.IsReady() && _wheels.IsReady() && _cockpit.IsReady();

}

}

public class Engine

{

public void Start()

{

}

public bool IsReady()

{

return true;

}

}

public class Aviation

{

private int _FuelLevel = 1000;

public bool IsReady()

{

return _FuelLevel > 5000; // Returns false as not enough fuel

}

}

public class Wheels

{

public bool IsReady()

{

return true;

}

}

public class Cockpit

{

public bool IsReady()

{

return true;

}

}

Please note that the Aviation class returns false for the IsReady() method. The FlightMediator constructor takes all the component classes as inputs. The IsReady() method checks all the associated component’s IsReady() method to ensure validations are right.

On running the Windows Forms application, you can see the following screen.

clip_image006

Clicking on the FlightMediator button you can see the color changing to red as the status returned is false.

clip_image008

Summary

In this article we have explore the Mediator pattern. The example is provided in a simple problem scenario, but the real world problems will be much complicated. For example a Wizard Page Framework where each page has to think about the previous and next pages could be made better using the Mediator pattern. The associated source code is attached with the article.

Posted in C# | Tagged: | Leave a Comment »

Iterator Pattern

Posted by JP on December 26, 2011

In this article we are going to discuss about the Iterator design pattern. Most of the Object Oriented Languages nowadays supports this pattern through their core language infrastructure.

clip_image002

Challenge

You are working on a Name printing application. You have to deal with a Bank class with the following properties.

public class Bank

{

public string ManagerName

{

get;

set;

}

public string AccountantName

{

get;

set;

}

public string CashierName

{

get;

set;

}

}

For printing the name the Print() method is called as following:

Print(_bank.Manager);

Print(_bank.Accountant);

Print(_bank.Cashier);

Now there is an addition of Branch type Bank to the above Bank object. Now the situation has become more complex. How to do a better approach?

Definition

“Provide a way to access the elements of an aggregate object sequentially

without exposing its underlying representation”

Implementation

We can improve the above Challenge Situation using the Iterator pattern. Instead of calling Print() method each time, we can use an Iterator to get the names inside Bank Object.

We are introducing a new class named BankIterator which implements IEnumerable:

public class BankIterator : IEnumerable

{

private IList _list = new ArrayList();

public BankIterator(Bank bank)

{

_list.Add(bank.Manager);

_list.Add(bank.Accountant);

_list.Add(bank.Cashier);

}

public IEnumerator GetEnumerator()

{

return _list.GetEnumerator();

}

}

The class uses and ArrayList ito hold the Manager, Accountant, Cashier names. As it is inheriting IEnumerable it has to implement the GetEnumerator() method. Luckily we can send the list.GetEnumerator() for the same.

The new Print() method invocation looks like below:

BankIterator iterator = new BankIterator(_bank);

foreach (string name in iterator)

Print(name);

This improves the situation in the following ways:

  • Easier Names access through Iteration
  • More flexibility in introducing new Name properties in the Bank class

Following is the snapshot of Class Diagrams:

clip_image004

Note

From C# 2.0 onwards the Iterator pattern is implemented using foreach. The foreach allows sequential accessing of the elements inside a collection. The IEnumerator interface is used to implement the Iterator pattern.

public interface IEnumerator

{

object Current { get; }

bool MoveNext();

void Reset();

}

While executing the foreach, first the Reset() method is called to position to the first element of the collection. Then through each iteration the MoveNext() method is called. The Current property returns the current object from the collection. The IEnumerator interface implementation of array, List, HashSet etc. enables us to iterate over them using the same foreach loop.

clip_image006

References

http://msdn.microsoft.com/en-us/library/dscyy5s0(v=vs.80).aspx

Summary

In this article we have explored the Iterator pattern with an example in C#. The pattern is already well implemented inside the language architecture of C#. We can extend the pattern usage in our custom classes too. The examples we discussed above are included in the source code attachment.

Posted in C# | Tagged: | Leave a Comment »

Facade Pattern

Posted by JP on December 22, 2011

In this article I would like to explore the Façade design pattern. The actual pronunciation is fu’saad. The dictionary meaning of the word Façade is “A showy misrepresentation intended to conceal something unpleasant”

Now let us enter the challenge..

Challenge

You are working on a database application. Frequently you need to execute UPDATE and DELETE SQL queries. Each time there is a need to create the SqlConnection and SqlCommand class, assign the connection to command and execute the query.

The series of activities looks like:

SqlConnection connection = new SqlConnection(“connection string” );

SqlCommand command = new SqlCommand();

command.Connection = connection;

command.CommandText = “UPDATE Customer SET Processed=1”;

command.ExecuteNonQuery();

You need to repeat the same code wherever execute queries are required. How to make this code better?

Definition

“Provide a unified interface to a set of interfaces in a system. Facade defines a higher-level interface that makes the subsystem easier to use.”

Implementation

Using Façade, we can improve the situation. We can find only the query is different in each case – the parameters like connection string is common for the entire application.

SQLFacade.ExecuteSQL(“UPDATE query here..”);

After using the Façade the code will look like above.

The complicated code is being pulled to the background SQLFacade class.

namespace FacadePattern

{

public class SQLFacade

{

public static bool ExecuteSQL(string sql)

{

SqlConnection connection = new SqlConnection(“connection string”);

SqlCommand command = new SqlCommand();

command.Connection = connection;

command.CommandText = sql;

command.ExecuteNonQuery();

return true;

}

}

}

Façade pattern makes code better as depicted in the image below:

clip_image002

Summary

In this article we have seen how to use the Façade pattern to improve our code. It is similar to the use of reusable functions and it pulls out the complications and provides an easier interface for use. The associated code contains the classes we have discussed.

Posted in Design Patterns | Tagged: | Leave a Comment »

Windows Azure – AppFabric Access Control Service – Introduction

Posted by JP on December 21, 2011

In this article we can explore the Access Control service of Windows Azure AppFabric. As you know the services provided by AppFabric are shown below.

clip_image002

Theory on Access Control

The Access Control Service (ACS) provides a flexible way of authentication and authorization in the cloud premises. The ACS extracts out the authentication and authorization code outside the application.

We can use ACS along with:

  • Web Applications
  • Web Services

Simply, the Access Control Service 2.0 allows us to integrate single sign on (SSO) and centralized authorization into the web applications.

In the old applications we need to incorporate the authentication and authorization code inside our applications. This will lead to mixing of business logic with the security overheads. The PrincipalPermission attribute, Cookie Presence Checking etc. are some of the ways of doing it. AppFabric through ACS provides a better way of dealing with security aspects.

Protocols: The following protocols are supported by ACS 2.0

  • WS-Trust
  • WS-Federation
  • OAuth

Identity Providers: The identity providers supported by ACS include:

  • Windows Live ID
  • Facebook
  • Google
  • Yahoo
  • WS-Federation Identity Providers

Compatibility: ACS is compatible with web platforms including:

  • .Net
  • PHP
  • Java
  • Ruby
  • Python

Difference between Old Application and Azure Application Security Aspects

clip_image004

Service Namespace: Like the Service Bus, we need to create a service namespace for the Access Control Service too. The services in a particular namespace share the same DNS name. The Service Namespace acts as a top level partition around the end points.

There are different endpoints inside the namespace:

  • Security Token Service
  • Management Service
  • Management Portal
  • Service Metadata

The format of the end point will be:

https://<servicenamespace&gt;.accesscontrol.windows.net/mgmt

Managed Namespace: A managed namespace is partially managed by another service. The Service Bus and Cache services uses managed namespaces characterized by –sb and –cache respectively.

Relying Party: In the context of ACS, relying party is an application for which we are implementing federated authentication. The configuration includes a term Realm which acts as the URI. There is a Return Url which is invoked to provide the token when the invoker is valid.

Example of Realm are: http://contesso.com. Any request with Realm prefix with http://contesso.com will be gaining valid tokens. We can also include http://localhost/ as a valid realm.

We can also configure an Error url which will be invoked during any problems in the login process. Eg: http://www.yourdomain/error.htm

The configuration of relying party application can be manual or through program. The relying party control flow is depicted below.

clip_image006

Rule Groups: A relying party application should be associated with at least one rule group. If the Real match one configured application which is not associated with any of the rule groups, the token will not be issued.

We can associate one rule group with more than one application and one application with more than one rule group.

Summary

In this article we have learnt about the AppFabric Access Control Service. It provides a better way of authentication and authorization. In the next article we can see how to create a service namespace and using the Access Control Service Portal.

Posted in Azure | Tagged: , , , | Leave a Comment »

State Pattern

Posted by JP on December 21, 2011

In this article I am going to explain the State Pattern. It is one among the 23 design patters and provides a good solution to a common problem. As usual the pattern starts with a challenge and then implementing the solution using the pattern.

Challenge

You are working on a job processing application. The application can handle only 1 job at a time. So when a new job arrives the system response will be weird. How to provide a better approach to the above problem?

Definition

Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.”

Implementation

An enumeration named JobState is used to define the states used in our application.

public enum JobState

{

Ready,

Busy

}

This enumeration is used inside our Job class.

public class Job

{

private JobState _State;

public JobState State

{

get { return _State; }

set

{

_State = value;

if (OnJobStateChanged != null)

OnJobStateChanged(this, _State);

}

}

public bool AddJob(object jobParameter)

{

switch (State)

{

case JobState.Ready:

{

DoJob();

return true;

}

case JobState.Busy:

{

return false;

}

}

return false;

}

}

In the AddJob() method we can see the new job is taken only if the JobState is in Ready state. Here true will be returned by the method. If there is another job running, then the new job will not be queued and false will be returned.

Thus the object Job changes the behavior based on the internal state.

Application

The associated application contains the classes we discussed.

On executing the windows application and clicking the Assign Job button, you can see the following screen:

clip_image002

While a job is in process, we cannot add another job. If a try is made the response is:

clip_image004

Summary

In this article we have seen about State Pattern. The attachment file contains the source code of the application we have discuseed.

Posted in Design Patterns | Tagged: | Leave a Comment »

uCertify Exam Evaluation

Posted by JP on December 14, 2011

I had an opportunity to review 70-542-CSHARP – MS Office SharePoint Server 2007 C#.NET Application Development PrepKit. The kit is really good and covers all the objective. I am sharing some of the cool features of the PrepKit.

uCertify Prepkit: Cool Features

Time is of essence

Anticipating your needs and customizing the material to your strengths and weaknesses is at the core of our unique PrepEngine.

Work smarter, not harder

We have created a unique blend of learning & test preparation, the foundation of which is working smarter. Gain the skills you need not just to pass the test, but to actually use them on the job!

Question Types (Eenie, Meenie, Minie, Mo)

Our PrepKits support all question type you are likely to see in actual exam.

Personalize to your Learning Style

Everyone learns differently, at their own pace.Our PrepEngine can work with any learning style.

Extreme Integration

Our Study guides and Practice questions are integrated such that if you are reviewing some study notes, and want to test your level of learning in that area, you can take a quiz on that particular topic. The reverse is true as well.

Comments, Bookmarks & Tags

Attach your own notes to questions, facts, study guides and more. Find something interesting or particularly hard? Bookmark or Tag it for easy future reference.

Guided Learning

You will find our products chock full of features from context based study notes that can be referenced during learning mode to tests that adapt themselves to your strengths and weaknesses on the subject.

Continuous feedback & Assessment

Starting with our diagnostic tests that show you where you stand initially, our continuous feedback gives you a precise idea of your exam readiness. The easy to read reports clearly show how ready you are and what to focus on.

Keyboard shortcuts – Navigate like a pro

Our PrepEngine supports keyboard shortcuts for frequently used actions. Select options and navigate without ever lifting your fingers from the keyboard.

Posted in C# | Tagged: , | 1 Comment »

Proxy Pattern

Posted by JP on December 7, 2011

In this article we are going to discuss about Proxy design pattern. It is one among the 23 design patterns by Gof. As usual we can start with the Challenge and Solution style.

Challenge

You are working on automating Excel COM objects. The business logic has to think too much about instantiating COM, doing ground works before calling the actual functionalities etc.

The same code could get replaced by DCOM tomorrow. So the Excel access code is spread throughout your application. How to do a better design?

clip_image002

Definition

“Provide a surrogate or placeholder for another object to control access to it.”

Implementation

We can solve the above problem by using a Proxy pattern. As the definition says, we will have to create a placeholder or wrapper around the original object to control access to it. In this way we can make the following advantages:

  • Talk to COM or DCOM Excel object by changing configuration in one place
  • Give application a simple interface to talk with Excel COM/DCOM
  • Feel application think like it is talking to a local object

Application

Following is the application with data:

clip_image004

Old Code

Following is the old code where application is forced to think too much about the Excel COM object and method of assigning values to the cells.

//Start Excel and get Application object.

Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();

oXL.Visible = true;

//Get a new workbook.

Microsoft.Office.Interop.Excel._Workbook oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));

Microsoft.Office.Interop.Excel._Worksheet oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet;

//Add table headers going cell by cell.

oSheet.Cells[1, 1] = “Name”;

oSheet.Cells[1, 2] = “Address”;

oSheet.Cells[1, 3] = “Salary”;

//Format A1:D1 as bold, vertical alignment = center.

oSheet.get_Range(“A1”, “C1”).Font.Bold = true;

oSheet.get_Range(“A1”, “C1”).VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;

int i = 2;

foreach (Employee employee in _list)

{

string[] values = new string[3];

values[0] = employee.Name;

values[1] = employee.Address;

values[2] = employee.Salary.ToString();

oSheet.get_Range(“A” + i.ToString(), “C” + i.ToString()).Value = values;

i++;

}

oXL.Visible = true;

oXL.UserControl = true;

The problem with above code is too much Excel logic is mixed with the application logic. Now we can see the new code with proxy pattern implemented.

New Code with Proxy Pattern

ExcelProxy proxy = new ExcelProxy();

proxy.Save(_list);

The code is only 2 lines and the Excel COM object creation, cell value assigning etc are taken care by the ExcelProxy class.

clip_image006

Application Execution

On executing the application we can see the results inside Microsoft Excel.

clip_image008

Other Examples of Proxy Pattern

We can have many real world examples which implement the Proxy pattern. When we add a WCF reference a Proxy is created. This class takes care of the connection details, serialization etc.

Summary

In this article we have seen the usage of Proxy design pattern along with an example. The source code attached contains the example we have discussed.

Posted in C# | Tagged: | Leave a Comment »

Flyweight Pattern

Posted by JP on December 6, 2011

In this article we are discussing about Flyweight Design Pattern. It is one among the 23 design patterns and provides an improved way of managing objects.

Challenge

You are working on an Id Card Creation web application. The application has 1 lakh Student records for which Id Cards to be created.

Following is the StudentCard class that performs the id card generation. We need to call the GenerateIdCard() method to get the Id Card image after assigning the student Name, Address, Photo properties. Each card image generated is saved to file system.

clip_image002

The problem is the 1 Lakh class instances created. How to reduce the number of instances?

Definition

“Use sharing to support large numbers of fine-grained objects efficiently.”

Implementation

Using Flyweight pattern we can solve the above problem. We can see from the above problem that at a time only one instance is needed.

We can use only one instance of StudentCard class and share it inside the loop to assign the properties and generate id card.

The pattern is advisable on:

  • To reduce the number of instances
  • Sharing properties which are common

This was the old process:

clip_image004

Here depending on the Student count, instances of StudentCard are created.

This will be the new process:

clip_image006

Here only 1 instance of StudentCard is created.

Code View

Following is the code implementing Flyweight pattern:

StudentCard card = new StudentCard();

card.CollegeName = “College of Advanced Sciences”; // CommonProp

for (int i = 1; i <= 100; i++)

{

card.Name = names[random.Next(0, names.Length – 1)];

card.Address = addresses[random.Next(0, addresses.Length – 1)];

card.Photo = photos[random.Next(0, photos.Length – 1)];

list.Add(new System.Web.UI.WebControls.Image()

{

ImageUrl = card.GenerateIdCard()

});

}

Screen Shot

On running the attached web application you can see the following output. The data like Name, Address and Photo are randomly generated.

clip_image008

Drawbacks

Although the Flyweight pattern solves many problems, I would like to list some of the possible drawbacks of using it.

– More configuration code is needed to switch between properties

– Reduces performance in a multi-threaded environment if locks are used

Summary

In this article we have explored Flyweight design pattern. The pattern helps us in reducing system resources if correctly used. The associated source code contains the example we have discussed. Please let me know your comments on the article.

Posted in Design Patterns | Tagged: | Leave a Comment »

Factory Method Pattern

Posted by JP on December 1, 2011

In the previous article you might have read about Abstract Factory. It says about abstracting a class with related objects. In this article we are discussing on Factory Method pattern. I am using the same ADO.NET Provider Factory class as example.

Let us see the challenge and evolve to the solution.

Challenge

You are working on a windows application. The application has 2 types of users based on the database license they have: Sql Server or Oracle.

So for each database operation you need to create the right database classes based on an enumeration DatabaseType.

public void InsertRecord()

{

if (AppContext.DatabaseType == DatabaseType.SqlServer)

{

SqlConnection connection = new SqlConnection();

SqlCommand command = new SqlCommand();

command.Connection = connection;

command.ExecuteNonQuery();

}

else if (AppContext.DatabaseType == DatabaseType.Oracle)

{

OracleConnection connection = new OracleConnection();

OracleCommand command = new OracleCommand();

command.Connection = connection;

command.ExecuteNonQuery();

}

}

The above code seems to be complex and needs repeating for each database operation spread throughout the application.

How to stop the repeating code and make things better?

Definition

“Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses.”

Implementation

The above problem can be resolved using Factory Method pattern. Here we provide an abstract class for defining the structure and associating all related objects (using Abstract Factory). Then the sub classes will be created deriving from this abstract class. The sub classes decide which classes to be instantiated.

The advantage is more quality and less code. Here we have to define an abstract class named DbProviderFactory. (already ADO.NET contains it)

public abstract class DbProviderFactory

{

public virtual DbCommand CreateCommand();

public virtual DbCommandBuilder CreateCommandBuilder();

public virtual DbConnection CreateConnection();

public virtual DbDataAdapter CreateDataAdapter();

public virtual DbParameter CreateParameter();

}

Then from the above abstract class we can derive concrete classes.

public class SqlClientFactory : DbProviderFactory

{

public override DbConnection CreateConnection()

{

return new SqlConnection();

}

public override DbCommand CreateCommand()

{

return new SqlCommand();

}

}

You can see from the above code SqlConnection() and SqlCommand() objects are created and supplied for DbConnection and DbCommand types respctively. Here DbConnection and DbCommand are other abstract classes.

Similary the Oracle implementation follows:

public class OracleClientFactory : DbProviderFactory

{

public override DbConnection CreateConnection()

{

return new OracleConnection();

}

public override DbCommand CreateCommand()

{

return new OracleCommand();

}

}

Replacing the Original Code

Now we are ready to replace our Insert() method code with the Factory Method classes. Here we are using an AppInit() code to create the factory which will be used throughout the application.

public void AppInit()

{

if (AppContext.DatabaseType == DatabaseType.SqlServer)

AppContext.DbProviderFactory = SqlClientFactory.Instance;

else if (AppContext.DatabaseType == DatabaseType.Oracle)

AppContext.DbProviderFactory = OracleClientFactory.Instance;

}

// NewInsertRecord method

private void NewInsertRecord()

{

DbConnection connection = AppContext.DbProviderFactory.CreateConnection();

DbCommand command = AppContext.DbProviderFactory.CreateCommand();

command.Connection = connection;

command.ExecuteNonQuery();

}

From the above code you can see that using Factory Method the code is reduced considerably but at a cost of new classes. The pattern provides much flexibility on adding a new database. (if another customer with PostgreSQL arrives J)

Abstract and Concrete Derivation

The following image depicts the relation between the abstract and concrete classes we have discussed.

clip_image002

Note

ADO.NET already includes the DbProviderFactory abstract class and concrete classes like SqlClientFactory, OleDbFactory etc. Additionally, using an ORM like Entity Framework automatically takes care of the database switching. The scenario mentioned here is for learning purposes.

Summary

In this method we have seen the Factory Method pattern. The example we discussed is included with the attachment.

Posted in Design Patterns | Tagged: , , | Leave a Comment »