Saturday, November 21, 2009

Difference in .Net

csharpwithdj.blogspot.com
What is the difference between a Thread and Process?
A process is a collection of virtual memory space, code, data, and system resources. A thread is code that is to be serially executed within a process. A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary thread. A process can have multiple threads in addition to the primary thread. Prior to the introduction of multiple threads of execution, applications were all designed to run on a single thread of execution.

When a thread begins to execute, it continues until it is killed or until it is interrupted by a thread with higher priority (by a user action or the kernel’s thread scheduler). Each thread can run separate sections of code, or multiple threads can execute the same section of code. Threads executing the same block of code maintain separate stacks. Each thread in a process shares that process’s global variables and resources.

What is the difference between System.Array.CopyTo and System.Array.Clone in .NET?
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy.

What is the difference between a DataReader and Dataset in ADO.NET?
A DataReader works in a connected environment, whereas DataSet works in a disconnected environment. A DataReader object represents a forward only, read only access to data from a source. It implements IDataReader & IDataRecord interfaces. For example, The SQLDataReader class can read rows from tables in a SQL Server data source. It is returned by the ExecuteReader method of the SQLCommand class, typically as a result of a SQL Select statement. The DataReader class' HasRows property can be called to determine whether the DataReader retrieved any rows from the source. This can be used before using the Read method to check whether any data has been retrieved.

Example

Dim objCmd as New SqlCommand("Select * from t_Employees", objCon)

objCon.Open()

Dim objReader as SqlDataReader

objReader =

objCom.ExecuteReader(CommandBehavior.CloseConnection)

If objReader.HasRows = True then

Do While objReader.Read()

ListBox1.Items.Add(objReader.GetString(0) & vbTab & objReader.GetInt16(1))

Loop

End If

objReader.Close()

(NOTE: XmlReader object is used for Forward only Read only access of XML).

A DataSet represents an in-memory cache of data consisting of any number of inter-related DataTable objects. A DataTable object represents a tabular block of in-memory data. Further, a DataRow represents a single row of a DataTable object. A Dataset is like a mini-database engine, but its data is stored in the memory. To query the data in a DataSet, we can use a DataView object.

Example

Dim objCon as SqlConnection = New SqlConnection("server=(local);database=NameOfYourDb;user id=sa; password=;)

Dim da as New SqlDataAdapter
Dim ds as DataSet = New DataSet
da.SelectCommand.Connection = objCon
'The Data Adapter manages on its own, opening & closing of connection object
da.SelectCommand.CommandText = "Select * from t_SomeTable"
da.Fill(ds,"YourTableName")

Suppose you want to bind the data in this dataset to a gridview

Gridview1.DataSource = ds
Gridview1.DataMember = "YourTableName"
Gridview1.Databind()

What is the difference between ExecuteScalar and ExecuteNonQuery? What is ExecuteReader?
ExecuteScalar - Returns only one value after execution of the query. It returns the first field in the first row. This is very light-weight and is perfect when all your query asks for is one item. This would be excellent for receiving a count of records (Select Count(*)) in an sql statement, or for any query where only one specific field in one column is required.

ExecuteNonQuery - This method returns no data at all. It is used majorly with Inserts and Updates of tables. It is used for execution of DML commands.

Example:

SqlCommand cmd = new SqlCommand("Insert Into t_SomeTable Values('1','2')",con);

//note that con is the connection object

con.Open();
cmd.ExecuteNonQuery(); //The SQL Insert Statement gets
executed

ExecuteReader - This method returns a DataReader which is filled with the data that is retrieved using the command object. This is known as a forward-only retrieval of records. It uses our SQL statement to read through the table from the first to the last record.

What is the difference between Authorization and Authentication?
Both Authentication and Authorization are concepts of providing permission to users to maintain different levels of security, as per the application requirement.

Authentication is the mechanism whereby systems may securely identify their users. Authentication systems depend on some unique bit of information known only to the individual being authenticated and the authentication system.

Authorization is the mechanism by which a system determines what level of access a particular authenticated user should have to secured resources controlled by the system. When a user logs on to an application/system, the user is first Authenticated, and then Authorized.

ASP.NET has 3 ways to Authenticate a user:

1) Forms Authentication
2) Windows Authentication
3) Passport Authentication (This is obsolete in .NET 2.0)
The 4th way is "None" (means no authentication)

The Authentication Provider performs the task of verifying the credentials of the user ans decides whether a user is authenticated or not. The authentication may be set using the web.config file.

Windows Authentication provider is the default authentication provider for ASP.NET applications. When a user using this authentication logs in to an application, the credentials are matched with the Windows domain through IIS.

There are 4 types of Windows Authentication methods:

1) Anonymous Authentication - IIS allows any user
2) Basic Authentication - A windows username and password has to be sent across the network (in plain text format, hence not very secure).
3) Digest Authentication - Same as Basic Authentication, but the credentials are encrypted. Works only on IE 5 or above
4) Integrated Windows Authentication - Relies on Kerberos technology, with strong credential encryption

Forms Authentication - This authentication relies on code written by a developer, where credentials are matched against a database. Credentials are entered on web forms, and are matched with the database table that contains the user information.

Authorization in .NET - There are two types:

FileAuthorization - this depends on the NTFS system for granting permission
UrlAuthorization - Authorization rules may be explicitly specified in web.config for different web URLs.

What is the difference between Server.Transfer and Response.Redirect?
Both "Server" and "Response" are objects of ASP.NET. Server.Transfer and Response.Redirect both are used to transfer a user from one page to another. But there is an underlying difference.

//Usage of Server.Transfer & Response.Redirect

Server.Transfer("Page2.aspx");
Response.Redirect("Page2.aspx");

The Response.Redirect statement sends a command back to the browser to request the next page from the server. This extra round-trip is often inefficient and unnecessary, but this established standard works very well. By the time Page2 is requested, Page1 has been flushed from the server’s memory and no information can be retrieved about it unless the developer explicitly saved the information using some technique like session, cookie, application, cache etc.

The more efficient Server.Transfer method simply renders the next page to the browser without an extra round trip. Variables can stay in scope and Page2 can read properties directly from Page1 because it’s still in memory. This technique would be ideal if it wasn’t for the fact that the browser is never notified that the page has changed. Therefore, the address bar in the browser will still show “Page1.aspx” even though the Server.Transfer statement actually caused Page2.aspx to be rendered instead. This may occasionally be a good thing from a security perspective, it often causes problems related to the browser being out of touch with the server. Say, the user reloads the page, the browser will request Page1.aspx instead of the true page (Page2.aspx) that they were viewing. In most cases, Response.Redirect and Server.Transfer can be used interchangeably. But in some cases, efficiency or usability may be the deciding factor in choosing.

What is the difference between Trace and Debug?
Trace and Debug - There are two main classes that deal with tracing - Debug and Trace. They both work in a similar way - the difference is that tracing from the Debug class only works in builds that have the DEBUG symbol defined, whereas tracing from the Trace class only works in builds that have the TRACE symbol defined. Typically this means that you should use System.Diagnostics.Trace.WriteLine for tracing that you want to work in debug and release builds, and

System.Diagnostics.Debug.WriteLine for tracing that you want to work only in debug builds. Tracing is actually the process of collecting information about the program's execution. Debugging is the process of finding & fixing errors in our program. Tracing is the ability of an application to generate information about its own execution. The idea is that subsequent analysis of this information may help us understand why a part of the application is not behaving as it should and allow identification of the source of the error.

We shall look at two different ways of implementing tracing in .NET via the System.Web.TraceContext class via the System.Diagnostics.Trace and System.Diagnostics.Debug classes. Tracing can be thought of as a better alternative to the response.writes we used to put in our classic ASP3.0 code to help debug pages.

If we set the Tracing attribute of the Page Directive to True, then Tracing is enabled. The output is appended in the web form output. Messeges can be displayed in the Trace output using Trace.Warn & Trace.Write.

NOTE The only difference between Trace.Warn & Trace.Write is that the former has output in red color. If the trace is false, there is another way to enable tracing. This is done through the application level. We can use the web.config file and set the trace attribute to true. Here we can set

Note that the Page Directive Trace attribute has precedence over th application level trace attribute of web.config. While using application level tracing, we can view the trace output in the trace.axd file of the project.

What is the difference between Web Services and Remoting?
Both Remoting and Web Services are ways of communication between applications.
Remoting - In remoting, the applications involved in the communication process may be located on the same computer, different computers in a same or different network. In remoting, both applications know about each other. A proxy of an application object is created on the other application.

Web Services - Communication between applications using web services is platform independent and programming independent. The application that consumes the web service, simply accesses it, without needing to know how this web service has actually been implemented & created.

Here are some of the major differences:

* ASP.NET Web Services may be accessed using HTTP only.

Remoting objects may be accessed over any protocol like TCP, SMTP, HTTP

* Web Service are Stateless, whereas Remoting has support for both stateless and with-state environment, which is achieved using Singleton and Singlecall activation

* ASP.NET provides good support to create Web Services. They are easy to deploy. In comparison, Remoting is little complex.

* Web services may be considered very reliable, due to the fact that they are hosted on IIS. In remoting, if IIS is'nt used, then methods like plumbing have to be used to ensure the application reliability.

* In .NET, when we create an application that consumes a web service, the web service may or may not be built using .NET.

But while implementing Remoting in .NET, both the applications must be built in .NET.

* Using web services, only a limited number of types may be serialized (XML). Using Remoting, objects like SOAP objects, Binary objects & XML Objects may be serialized.

What is the difference between String and StringBuilder?
Both String and StringBuilder are classes used to handle strings.

The most common operation with a string is concatenation. This activity has to be performed very efficiently. When we use the "String" object to concatenate two strings, the first string is combined to the other string by creating a new copy in the memory as a string object, and then the old string is deleted. This process is a little long. Hence we say "Strings are immutable".

When we make use of the "StringBuilder" object, the Append method is used. This means, an insertion is done on the existing string. Operation on StringBuilder object is faster than String operations, as the copy is done to the same location. Usage of StringBuilder is more efficient in case large amounts of string manipulations have to be performed.

What is the difference between a Class Library and a Namespace?
Class Library is another major entity of the .NET Framework (the other being the CLR). This library gives the program access to runtime environment. The class library consists of lots of prewritten code that all the applications created in .NET will use. The code for all the elements like forms, controls actually comes from the class library. The main class library in .NET is mscorlib.dll. This library contains a large number of core types that encapsulate a wide variety of common tasks. When a .NET application, there is automatic access to this library. We may view the class libraries provided by the .NET Framework by seeing the Global Assembly Cache (Go to C:\Windows\Assembly OR C:\Winnt\Assembly).

Namespace is a grouping of related types contained in an assembly. For example, the System.Drawing namespace consists of classes, methods that are grouped together to achieve similar tasks.

Note that a single assembly like mscorlib.dll may contain any number of namespaces. In fact, namespaces may be nested (means a namespace within a namespace) to arrange classes in a hierarchical fashion. Also note that any language, that works on the .NET environment, targets the same set of namespaces & types provided by the .NET framework.

What is the difference between a DLL and an EXE?
In .NET, an assembly may become a DLL or an EXE. Yet, there is a major underlying difference between the two.

An EXE is an executable file, that may run on its own. Its independant. Where as a DLL is a Dynamic Link Library, that binds to an exe, or another DLL at runtime.

A DLL has an exposed interface, through which members of the assembly may be accessed by those objects that require it.

A DLL runs in tandem with the application space in memory, as the application references it. Whereas an EXE is independant, and runs as an independant process.

What is the difference between value type and reference type? Can a value type contain NULL values?
In simple words, all value based types are allocated on the stack, while all reference based types are allocated on the heap. What does this mean? A value type contains the actual value. A reference type contains a reference to the value. When a value type is assigned to another value type, it is copied. When a reference type is assigned to another reference type, a reference is assigned to the value. By saying stack, we mean things are kept one on top of the other. We keep track of each value at the top. By saying heap, we mean things are kept in a mashed order. We keep track of each value by its address, that is referenced by a pointer to it.

All value types are implicitly derived from System.ValueType. This class actually overrides the implementation in System.Object, the base class for all objects which is a reference type itself.

Data types like integers, floating point numbers, character data, Boolean values, Enumerations and Structures are examples of Value Types. Classes, Strings, Arrays are examples of Reference Types.

A value type may not contain NULL values. Reference types may contain NULL values.

It is not possible to derive new types from Value Types. This is possible in Reference types. However, Value Types like Structures can implement interfaces.

What is the difference between Shared and Static?
They both mean the same.

Shared is used in VB.NET.
Static is used in C#.

When the static keyword is used to declare a class, the member in context must be directly invoked from the class, rather than from the instance. Consider the following example

//Consider writing the following line of code...

Console obj = new Console(); obj.Writeline("Vishal likes static members"); //This line does'nt print

//This does'nt work, because WriteLine is a static method defined in the class Console

//The Console class is a static class

To use static members, give a reference to the exact class, as an instance in this case won't work.

To make this work, write...

Console.Writeline("Vishal likes static members");

To work with members of static classes, no need to create their instances.

Static Member - A class member declared with the keyword static is a static member. A static member is owned by the class, not by its instances (objects of the class).

Note that static members are actually class members, while non-static members are instance members (means they are owned by the instances). Both in C# & VB.NET, we may create static/shared events, properties, fields and functions.

Note Indexers in C# cannot be declared static.

Note Static member functions cannot access non-static members directly.

Whats the difference between a class and an object?
In any object Oriented language, an object is the backbone of everything that we see. A class is a blueprint that describes how an instance of it (object) will behave. To create a class, we define it in a "Code File", with an extension *.cs or *.vb. We make use of the keyword class.

Example
Lets create a class named Laptop

public class Laptop
{
private string sbrand;
public Laptop() {}
public Laptop(string name)
{
sbrand = name;
}
}
From our code that references this class, we write...

Laptop lp = new Laptop("Lenovo"); //Passing a variable to the class constructor

Once the class object is created, the object may be used to invoke the member functions defined within the class. We may allocate any number of objects using the new keyword. The new keyword returns a reference to an object on the heap. This reference is not to the actual object itself. The variable being refered is stored on a stack for usage in the application. When we allocate an object to a heap, its managed by the .NET runtime. The garbage collector takes care of the object by removing it from the heap, when it is no longer reachable by any part of the code.

What is the difference between Overriding and Shadowing?
Both Overriding and Shadowing are ways to alter the behaviour of members of a base class. Shadowing is a VB.NET concept. In C#, this concept is called Hiding, though there is a difference between the two.

When we do shadowing, we provide a new implementation to the base class member without overriding it. We may shadow a base Class member in a derived class, by using the keyword shadows.

The access level, return type, and the signature (means the datatypes of the arguments passed & the order of the types) of the derived class members which are shadowed, may differ from the base class. In C#, we may achieve shadowing using the keyword new. However, when Hiding in C#, the access level, the signature, return type of the derived class must be same as the base class.

Overriding is the concept of providing a new implementation of derived class member as compared to its based class. In VB.NET, we do overriding using the overrides keyword, while in C#, overriding is achieved using the override keyword. For a class member to be overridable, we use the keyword virtual while defining it (in C#), and we use the keyword overridable (in VB.NET), though if we leave out specifying the overridable keyword, the member is overridable by default.

Explain the access specifiers Public, Private, Protected, Friend, Internal, Default
The main purpose of using access specifiers is to provide security to the applications. The availability (scope) of the member objects of a class may be controlled using access specifiers.

1. PUBLIC

As the name specifies, it can be accessed from anywhere. If a member of a class is defined as public then it can be accessed anywhere in the class as well as outside the class. This means that objects can access and modify public fields, properties, methods.

2. PRIVATE

As the name suggests, it can't be accessed outside the class. Its the private property of the class and can be accessed only by the members of the class.

3. FRIEND/INTERNAL

Friend & Internal mean the same. Friend is used in VB.NET. Internal is used in C#. Friends can be accessed by all classes within an assembly but not from outside the assembly.

4. PROTECTED

Protected variables can be used within the class as well as the classes that inherites this class.

5. PROTECTED FRIEND/PROTECTED INTERNAL

The Protected Friend can be accessed by Members of the Assembly or the inheriting class, and ofcourse, within the class itself.

6. DEFAULT

A Default property is a single property of a class that can be set as the default. This allows developers that use your class to work more easily with your default property because they do not need to make a direct reference to the property. Default properties cannot be initialized as Shared/Static or Private and all must be accepted at least on argument or parameter.

Default properties do not promote good code readability, so use this option sparingly.

What is the difference between abstract class and interface?
If a class is to serve the purpose of providing common fields and members to all subclasses, we create an Abstract class. For creating an abstract class, we make use of the abstract keyword. Such a class cannot be instantiated. Syntax below:

abstract public class Vehicle { }

Above, an abstract class named Vehicle has been defined. We may use the fields, properties and member functions defined within this abstract class to create child classes like Car, Truck, Bike etc. that inherit the features defined within the abstract class. To prevent directly creating an instance of the class Vehicle, we make use of the abstract keyword. To use the definitions defined in the abstract class, the child class inherits from the abstract class, and then instances of the Child class may be easily created. Further, we may define abstract methods within an abstract class (analogous to C++ pure virtual functions) when we wish to define a method that does not have any default implementation. Its then in the hands of the descendant class to provide the details of the method. There may be any number of abstract methods in an abstract class. We define an abstract method using the abstract keyword. If we do not use the abstract keyword, and use the virtual keyword instead, we may provide an implementation of the method that can be used by the child class, but this is not an abstract method. Remember, abstract class can have an abstract method, that does not have any implementation, for which we use the abstract keyword, OR the abstract class may have a virtual method, that can have an implementation, and can be overriden in the child class as well, using the override keyword. Read example below

Example: Abstract Class with Abstract method

namespace Automobiles
{
public abstract class Vehicle
{
public abstract void Speed() //No Implementation here, only definition
}
}

Example: Abstract Class with Virtual method

namespace Automobiles
{
public abstract class Vehicle
{
public virtual void Speed() //Can have an implementation, that may be overriden in child class
{
...
}

}

Public class Car : Vehicle
{
Public override void Speed()

//Here, we override whatever implementation is there in the abstract class
{
... //Child class implementation of the method Speed()

}

}

}

An Interface is a collection of semantically related abstract members. An interface expresses through the members it defines, the behaviors that a class needs to support. An interface is defined using the keyword interface. The members defined in an interface contain only definition, no implementation. The members of an interface are all public by default, any other access specifier cannot be used. See code below:

Public interface IVehicle //As a convention, an interface is prefixed by letter I
{

Boolean HasFourWheels()

}
 

  Difference between Abstract Class and Interface
1) A class may inherit only one abstract class, but may implement multiple number of Interfaces. Say a class named Car needs to inherit some basic features of a vehicle, it may inherit from an Aabstract class named Vehicle. A car may be of any kind, it may be a vintage car, a sedan, a coupe, or a racing car. For these kind of requirements, say a car needs to have only two seats (means it is a coupe), then the class Car needs to implement a member field from an interface, that we make, say ICoupe.

2) Members of an abstract class may have any access modifier, but members of an interface are public by default, and cant have any other access modifier.

3) Abstract class methods may OR may not have an implementation, while methods in an Interface only have a definition, no implementation.

Whats the difference betweeen Structure, Class and Enumeration
Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory.

Classes are Reference-Types, means they are stored as a heap on the memory. Structures are implicitly derived from a class called System.ValueType. The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved. When we allocate a structure type, we may also use the new keyword. We may even make a constructor of a structure, but, remember, A No-argument constructor for a structure is not possible. The structure's constructor should always have a parameter. So if we define the following structure

struct MyStruct
{
public int y,z;
}
and we create a structure type
MyStruct st = new MyStruct();
In case of a class, no-argument constructors are possible.
Class is defined using the class keyword.

A struct cannot have an instance field, whereas a class can.
class A
{
int x = 5; //No error
...
}
struct
{
int x = 5; //Syntax Error
}


A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit from a structure.

Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is "int". Note: char cant be the underlying data type for enum. First value in enum has value 0, each consequent item is increased by 1. enum colors {red, green, blue, yellow};

Here, red is 0, green is 1, blue is 2 and so on.

An explicit casting is required to convert an enum value to its underlying type

int x = (int)colors.yellow;


Difference Between Web Services and  Window Services 
An XML Web service is a component that implements program logic and provides functionality for disparate applications. These applications use standard protocols, such as HTTP, XML, and SOAP, to access the functionality. XML Web services use XML-based messaging to send and receive data, which enables heterogeneous applications to interoperate with each other. You can use XML Web services to integrate applications that are written in different programming languages and deployed on different platforms. In addition, you can deploy XML Web services within an ?intranet as well as on the Internet. While the Internet brings users closer to organizations, XML Web services allow organizations to integrate their applications.

Windows services run as background processes. These applications do not have a user interface, which makes them ideal for tasks that do not require any user interaction. You can install a Windows service on any server or computer that is running Windows 2000, Windows XP, or Windows NT. You can also specify a Windows service to run in the security context of a specific user account that is different from the logged on user account or the default computer account. For example, you can create a Windows service to monitor performance counter data and react to threshold values in a database.

Design Pattern Interview Question

What is a Design Pattern?


Design Pattern is a re-usable, high quality solution to a given requirement, task or recurring problem. Further, it does not comprise of a complete solution that may be instantly converted to a code component, rather it provides a framework for how to solve a problem.

Because design patterns consist of proven reusable architectural concepts, they are reliable and they speed up software development process.

Design Patterns are in a continious phase of evolution, which means that they keep on getting better & better as they are tested against time, reliability and subjected to continious improvements. Further, design patterns have evolved towards targeting specific domains. For example, windows-based bankin applications are usually based on singleton patterns, e-commerce web applications are based on the MVC (Model-View-Controller) pattern.

Design Patterns are categorized into 3 types:

Creational Patterns
Structural Patterns
Behavioral Patterns

What are Creational Design Patterns?

The Creational Design Patterns focus on how objects are created and utilized in an application. They tackle the aspects of when and how objects are created, keeping in mind whats the best way these objects should be created. Listed below are some of the commonly known Creational Design Patterns:

 Abstract Factory Pattern
Factory Pattern
Builder Pattern
Lazy Pattern
 Prototype Pattern
 Singleton Pattern

Whats the difference between Abstract Factory Pattern and Factory Pattern?

In an abstract factory design, a framework is provided for creating sub-components that inherit from a common component.

In .NET, this is achieved by creating classes that implement a common interface or a set of interfaces, where the interface comprises of the generic method declarations that are passed on to the sub-components. TNote that not just interfaces, but even abstract classes can provide the platform of creating an application based on the abstract factory pattern. Example, say a class called CentralGovernmentRules is the abstract factory class, comprised of methods like ShouldHavePolice() and ShouldHaveCourts(). There may be several sub-classes like State1Rules, State2Rules etc. created that inheriting the class CentralGovernmentRules, and thu deriving its methods as well.Note that the term "Factory" refers to the location in the code where the code is created.

A Factory Pattern is again an Object creation pattern. Here objects are created without knowing the class of the object. Sounds strange? Well, actually this means that the object is created by a method of the class, and not by the class's constructor. So basically the Factory Pattern is used wherever sub classes are given the priviledge of instantiating a method that can create an object.

Describe the Builder Design Pattern

In a builder design pattern, an object creation process is separated from the object design construct. This is useful becuase the same method that deals with construction of the object, can be used to construct different design constructs.

What is the Lazy Design Pattern?

The approach of the Lazy Design Pattern is not to create objects until a specific requirement matches, and when it matches, object creation is triggered. A simple example of this pattern is a Job Portal application. Say you register yourself in that site thus filling up the registration table, only when the registration table is filled, the other objects are created and invoked, that prompt you to fill in other details too, which will be saved in other tables.

What is the Prototype Design Pattern?

A prototype design pattern relies on creation of clones rather than objects. Here, we avoid using the keyword 'new' to prevent overheads.

What is the Singleton Design Pattern?

The Singleton design pattern is based on the concept of restricting the instantiation of a class to one object. Say one object needs to perform the role of a coordinator between various instances of the application that depend on a common object, we may design an application using a Singleton. Usage of Singleton patterns is common in Banking, Financial and Travel based applications where the singleton object consists of the network related information.

A singleton class may be used to instantiate an object of it, only if that object does not already exist. In case the object exists, a reference to the existing object is given. A singleton object has one global point of access to it.

An ASP.NET Web Farm is also based on the Singleton pattern. In a Web Farm, the web application resides on several web servers. The session state is handled by a Singleton object in

the form of the aspnet_state.exe, that interacts with the ASP.NET worker process running on each web server. Note that the worker process is the aspnet_wp.exe process. Imagine one of the web servers shutting down, the singleton object aspnet_state.exe still maintains the session state information across all web servers in the web farm.

In .NET, in order to create a singleton, a class is created with a private constructor, and a "static readonly" variable as the member that behaves as the instance.


What are Structural Design Patterns?

A structural design pattern establishes a relationship between entities. Thus making it easier for different components of an application to interact with each other. Following are some of the commonly known structural patterns:

 Adapter Pattern - Interfaces of classes vary depending on the requirement.
 Bridge Pattern - Class level abstraction is separated from its implementation.
 Composite Pattern - Individual objects & a group of objects are treated similarly in this approach.
Decorator Pattern - Functionality is assigned to an object.
Facade Pattern - A common interface is created for a group of interfaces sharing a similarity.
Flyweight Pattern - The concept of sharing a group of small sized objects.
Proxy Pattern - When an object is complex and needs to be shared, its copies are made.

These copies are called the proxy objects.

What are the different types of Proxy Patterns?

1 - Remote Proxy - A reference is given to a different object in a different memory location. This may be on a different or a same machine.

2 - Virtual Proxy - This kind of object is created only & only when really required because of its memory usage.

3 - Cache Proxy - An object that behaves as a temporary storage so that multiple applications may use it. For example,

in ASP.NET when a page or a user control contains the OutputCache directive, that page/control is cached for some time on the ASP.NET web server.


What is a behavioral design pattern?

Behaviorial design patterns focus on improving the communication between different objects.

Following are different types of behavioral patterns:

 Chain Or Responsibilities Pattern - In this pattern, objects communicate with each other depending on logical decisions made by a class.

 Command Pattern - In this pattern, objects encapsulate methods and the parameters passed to them.  Observer Pattern - Objects are created depending on an events results, for which there are event handlers created.


What is the MVC Pattern (Model View Controller Pattern)?

The MVC Pattern (Model View Controller Pattern) is based on the concept of designing an application by dividing its functionalities into 3 layers. Its like a triad of components. The Model component contains the business logic, or the other set of re-usable classes like classes pertaining to data access, custom control classes, application configuration classes etc. The Controller component interacts with the Model whenever required. The control contains events and methods inside it, which are raised from the UI which is the View component.Consider an ASP.NET web application. Here, all aspx, ascx, master pages represent the View.The code behind files (like aspx.cs, master.cs, ascx.cs) represent the Controller.The classes contained in the App_Code folder, or rather any other class project being referenced from this application represent the Model component.


Advantages: * Business logic can be easily modified, without affecting or any need to make changes in the UI.

* Any cosmetic change in the UI does not affect any other component.


What is the Gang of Four Design Pattern?

The history of all design patterns used in modern day applications derive from the Gang of Four (GoF) Pattern. Gang of Four patterns are categorized into 3 types:

1 - Creational
2 - Structural
3 - Behavioral

The term "Gang of Four" (or "GoF" in acronym) is used to refer to the four authors of the book Design Patterns: Elements of Reusable Object-Oriented Software. The authors are Erich Gamma, Ralph Johnson, Richard Helm and John Vlissides.


When should design patterns be used?

While developing software applications, sound knowledge of industry proven design patterns make the development journey easy and successful. Whenever a requirement is recurring, a suitable design pattern should be identified. Usage of optimal design patterns enhance performance of the application. Though there are some caveats. Make sure that there are no overheads imposed on a simple requirement, which means that design patterns should not be unnecessarily be used.


How many design patterns can be created in .NET?

As many as one can think. Design patterns are not technology specific, rather their foundation relies on the concept of reusability, object creation and communication. Design patterns can be created in any language.


Describe the Ajax Design Pattern.

In an Ajax Design Pattern, partial postbacks are triggered asyncronously to a web server for getting live data. A web application would not flicker here, and the web site user would not even come to know that a request is being sent to the web server for live data. Such a design pattern is used in applications like Stock Market Websites to get live quotes, News Webites for live news, Sports websites for live scores etc.