Design Patterns for all – Chapter III (Factory Pattern)
Tuesday, June 30, 2009
This is a series of articles which explain Design Patterns in detail with C# examples. In the previous chapter we saw the Singleton Design pattern. In this chapter we are going to see the Factory Pattern in detail with c# coding. Factory pattern is one of the widely used Design Patterns in the Object oriented programming world.
Definition:
A Factory Patterns creates an Interface for creating object and lets subclass do the instantiation. A Factory Pattern lets a class to defer instantiation to the subclasses. Simply saying it abstracts the instance creation.
Overview:
It lets the developer create an interface and retains which class needs to be instantiated. The Factory pattern comes under the category of Creational Patterns.
Generally when we create a class, we will provide constructors to the users of the class so they can create instances for the classes. But on some situations we need or should not give them the ability to create instances with the available classes. On such situations we can create Factory Pattern. That is rather than calling the constructors for creating objects, you are calling the Factory to create objects.
Its primary purpose is to create objects like a real work Factory.
Logical Model:
The prime actors of the Factory Pattern are:
· Client
· Factory
· Product
Product:
A product can be anything you produce in the factory. In programmatic angle it will the actual object which needs to be created.
Factory:
A Factory is the one who creates object of the product.
Client:
A client instead of directly creating objects of the product uses the Factory to create objects for it. The client is not aware about how the objects are created.
Factory Pattern in .net Framework:
Some of the areas where Factory Pattern is used are given below,
· IClassFactory is an interface used to create instances of COM classes.
· System.Web.IHttpHandlerFactory class
· System.Convert
Example in C#:
In this example we are going to create we use Abstract classes instead of Interfaces as Abstract classes has the benefits like versioning, etc., over Interfaces.
using System;
using System.Collections.Generic;
using System.Text;
namespace FactoryDemo
{
abstract class Car
{
public abstract int Speed { get; }
}
abstract class CarFactory
{
public abstract Car ShowCar();
}
//Concrete is nothing but the implementaion for the absract classes
class ConcreteCar : Car
{
int _speed = 300;
public override int Speed
{
get { return _speed; }
}
}
class ConcreteCarFactory : CarFactory
{
public override Car ShowCar()
{
return new ConcreteCar();
}
}
class CarCompany
{
public void ProduceCar(CarFactory objfac)
{
Car mycar = objfac.ShowCar();
Console.Write("Car Produced with speed: " + mycar.Speed);
Console.Read();
}
}
class Program
{
static void Main(string[] args)
{
CarFactory mycarfactory = new ConcreteCarFactory();
new CarCompany().ProduceCar(mycarfactory);
}
}
}
Here the abstract classes Car and CarFactory provides the interface and the classes ConcreteCar and ConcreteCarFactory provides the implementation for the abstract classes. The CarCompany class uses all these to make the factory work.
In the simillar way you can create as many of Cars with different model like RollsRoye, Honda and there by creating classes for them by inheriting the classes Car and CarFactory.
But remember that the CarCompany class is abstracted from other classes.
www.codecollege.NET
Design Patterns for all – Chapter III (Factory Pattern)
This is a series of articles which explain Design Patterns in detail with C# examples. In the previous chapter we saw the Singleton Design pattern. In this chapter we are going to see the Factory Pattern in detail with c# coding. Factory pattern is one of the widely used Design Patterns in the Object oriented programming world.
Definition:
A Factory Patterns creates an Interface for creating object and lets subclass do the instantiation. A Factory Pattern lets a class to defer instantiation to the subclasses. Simply saying it abstracts the instance creation.
Overview:
It lets the developer create an interface and retains which class needs to be instantiated. The Factory pattern comes under the category of Creational Patterns.
Generally when we create a class, we will provide constructors to the users of the class so they can create instances for the classes. But on some situations we need or should not give them the ability to create instances with the available classes. On such situations we can create Factory Pattern. That is rather than calling the constructors for creating objects, you are calling the Factory to create objects.
Its primary purpose is to create objects like a real work Factory.
Logical Model:
The prime actors of the Factory Pattern are:
· Client
· Factory
· Product
Product:
A product can be anything you produce in the factory. In programmatic angle it will the actual object which needs to be created.
Factory:
A Factory is the one who creates object of the product.
Client:
A client instead of directly creating objects of the product uses the Factory to create objects for it. The client is not aware about how the objects are created.
Factory Pattern in .net Framework:
Some of the areas where Factory Pattern is used are given below,
· IClassFactory is an interface used to create instances of COM classes.
· System.Web.IHttpHandlerFactory class
· System.Convert
Example in C#:
In this example we are going to create we use Abstract classes instead of Interfaces as Abstract classes has the benefits like versioning, etc., over Interfaces.
using System;
using System.Collections.Generic;
using System.Text;
namespace FactoryDemo
{
abstract class Car
{
public abstract int Speed { get; }
}
abstract class CarFactory
{
public abstract Car ShowCar();
}
//Concrete is nothing but the implementaion for the absract classes
class ConcreteCar : Car
{
int _speed = 300;
public override int Speed
{
get { return _speed; }
}
}
class ConcreteCarFactory : CarFactory
{
public override Car ShowCar()
{
return new ConcreteCar();
}
}
class CarCompany
{
public void ProduceCar(CarFactory objfac)
{
Car mycar = objfac.ShowCar();
Console.Write("Car Produced with speed: " + mycar.Speed);
Console.Read();
}
}
class Program
{
static void Main(string[] args)
{
CarFactory mycarfactory = new ConcreteCarFactory();
new CarCompany().ProduceCar(mycarfactory);
}
}
}
Here the abstract classes Car and CarFactory provides the interface and the classes ConcreteCar and ConcreteCarFactory provides the implementation for the abstract classes. The CarCompany class uses all these to make the factory work.
In the simillar way you can create as many of Cars with different model like RollsRoye, Honda and there by creating classes for them by inheriting the classes Car and CarFactory.
But remember that the CarCompany class is abstracted from other classes.
www.codecollege.NET
What is an Index and its Types and Differences between them ?
What is an Index and its Types and Differences between them ?
What is an Index?
Indexing is a mechanism which makes record
fetching faster. It does this by having pre-sorted the rows of the table.
Types of Indexes:
- Clustered.
- Non-Clustered.
Sno | Clustered | Non - Clustered |
1 | It reorders the physical storage of records in the table. | It sorts and maintain a separate storage. |
2 | There can be only one Clustered index per table. | More than one. |
3 | The leaf nodes contain data | The leaf node contains pointer to data |
What is an Index and its Types and Differences between them ?
What is an Index and its Types and Differences between them ?
What is an Index?
Indexing is a mechanism which makes record
fetching faster. It does this by having pre-sorted the rows of the table.
Types of Indexes:
- Clustered.
- Non-Clustered.
Sno | Clustered | Non - Clustered |
1 | It reorders the physical storage of records in the table. | It sorts and maintain a separate storage. |
2 | There can be only one Clustered index per table. | More than one. |
3 | The leaf nodes contain data | The leaf node contains pointer to data |
Daily Tips- Tip #3 - Automatically closing a connection after datareader finishes execution
To automatically close a connection after datareader finishes execution, you need to specify the CommandBehaviour.CloseConnection parameter to the command object, as
drEmployees = cmdEmployees.ExecuteReader(CommandBehaviour.CloseConnection);
Daily Tips- Tip #3 - Automatically closing a connection after datareader finishes execution
To automatically close a connection after datareader finishes execution, you need to specify the CommandBehaviour.CloseConnection parameter to the command object, as
drEmployees = cmdEmployees.ExecuteReader(CommandBehaviour.CloseConnection);
What are the uses of Views?
1. Views are virtual tables (they dont store data physically) which gives a result
of data by joining tables. So you are not storing redundant data.
2. Views are used to produce reports from data
3. Views can be used to provide security to data by giving access only to views.
What are the uses of Views?
1. Views are virtual tables (they dont store data physically) which gives a result
of data by joining tables. So you are not storing redundant data.
2. Views are used to produce reports from data
3. Views can be used to provide security to data by giving access only to views.
Daily Tips- Tip #2 - How to prevent .DLL Decompilation?
Monday, June 29, 2009
How to prevent .DLL Decompilation?
If have written some worthful code and if you dont want it to be decompiled by anybody, then you have to make it secure.
Obfuscation:
The process by which you make your assembly not decompilable is called as Obfuscation.
Popular Tools available are :
XenoCode, Demeanor
Websites:
htt://www.xenocode.com
http://www.wiseowl.com
remotesoft
>rustemsoft
Daily Tips- Tip #2 - How to prevent .DLL Decompilation?
How to prevent .DLL Decompilation?
If have written some worthful code and if you dont want it to be decompiled by anybody, then you have to make it secure.
Obfuscation:
The process by which you make your assembly not decompilable is called as Obfuscation.
Popular Tools available are :
XenoCode, Demeanor
Websites:
htt://www.xenocode.com
http://www.wiseowl.com
remotesoft
>rustemsoft
Daily Tips- Tip #1 - How can we force all the validation controls in a page to run?
Sunday, June 28, 2009
For that call this code,
Page.Validate();
What is the name of the class used to read and get details of the files uploaded to asp.net?
System.Web.HttpPostedFile
Differences between Dataset and DataReader
Sno | Dataset | DataReader |
1 | Disconnected Mode | Connected Mode |
2 | Can navigate back and forth | Can navigate forward only |
3 | Data is editable | Data is Readonly |
4 | Can contain more than one table and relationships | Can contain only one row at a time. |
5 | Slower as having more overhead | Faster when compared with dataset. |
Daily Tips- Tip #1 - How can we force all the validation controls in a page to run?
For that call this code,
Page.Validate();
What is the name of the class used to read and get details of the files uploaded to asp.net?
System.Web.HttpPostedFile
Differences between Dataset and DataReader
Sno | Dataset | DataReader |
1 | Disconnected Mode | Connected Mode |
2 | Can navigate back and forth | Can navigate forward only |
3 | Data is editable | Data is Readonly |
4 | Can contain more than one table and relationships | Can contain only one row at a time. |
5 | Slower as having more overhead | Faster when compared with dataset. |
Links for Asp.net Http Modules and Http Handlers
Http Modules and Http Handler
========================
http://support.microsoft.com/kb/307985
How To Create an ASP.NET HTTP Handler by Using Visual C# .NET
================================================
http://support.microsoft.com/kb/308001/EN-US/
Intercept, Monitor, and Modify Web Requests with HTTP Filters in ISAPI and ASP.NET
==================================================================
http://msdn.microsoft.com/hi-in/magazine/cc301704(en-us).aspx
Some more samples
================
http://www.informit.com/articles/article.aspx?p=25339&seqNum=3
Links for Asp.net Http Modules and Http Handlers
Http Modules and Http Handler
========================
http://support.microsoft.com/kb/307985
How To Create an ASP.NET HTTP Handler by Using Visual C# .NET
================================================
http://support.microsoft.com/kb/308001/EN-US/
Intercept, Monitor, and Modify Web Requests with HTTP Filters in ISAPI and ASP.NET
==================================================================
http://msdn.microsoft.com/hi-in/magazine/cc301704(en-us).aspx
Some more samples
================
http://www.informit.com/articles/article.aspx?p=25339&seqNum=3
How to force Garbage Collector?
How to force Garbage Collector?
What is assemblyInfo.cs file? Where can I find it? What is it for?
It consists of all build options for the project,including verison,company name,etc.
Where
It is located in the Properties folder.
Use
It is used to manage the build settings.
What is assemblyInfo.cs file? Where can I find it? What is it for?
It consists of all build options for the project,including verison,company name,etc.
Where
It is located in the Properties folder.
Use
It is used to manage the build settings.
Oslo - The Microsoft's Modeling platform
Oslo is the code name for Microsoft's Modeling platform .
"Oslo" was first announced by Robert Wahbe in October 2007.
Microsoft says that oslo consists of the following:
*A tool that helps people define and interact with models in a rich and visual manner
*A language that helps people create and use textual domain-specific languages and data models
*A relational repository that makes models available to both tools and platform components
For more information about oslo, read the following:
http://www.microsoft.com/NET/Oslo.aspx
Watch videos about oslo,
mms://msstudios.wmod.llnwd.net/a2294/o21/presspass/modeling9_10_MBR.wmv
http://msstudios.vo.llnwd.net/o21/presspass/zune/Looking_Ahead_Zune.wmv
Oslo - The Microsoft's Modeling platform
Oslo is the code name for Microsoft's Modeling platform .
"Oslo" was first announced by Robert Wahbe in October 2007.
Microsoft says that oslo consists of the following:
*A tool that helps people define and interact with models in a rich and visual manner
*A language that helps people create and use textual domain-specific languages and data models
*A relational repository that makes models available to both tools and platform components
For more information about oslo, read the following:
http://www.microsoft.com/NET/Oslo.aspx
Watch videos about oslo,
mms://msstudios.wmod.llnwd.net/a2294/o21/presspass/modeling9_10_MBR.wmv
http://msstudios.vo.llnwd.net/o21/presspass/zune/Looking_Ahead_Zune.wmv
What is Serialization ? What are the Types of Serialization and their differences?
It is the process of converting an object to a form suitable for either making it persistent or tranportable.
Deserialization is the reverse of this and it converts the object from the serialized state to its original state.
Types:
1. Binary
2. XML
Differences:
Sno | Binary | XML |
1 | It preserves type fidelity , which is useful for preserving the state of the object between transportation and invocation. | It doesnt preserves type fidelity and hence state cant be maintained. |
2 | As it is the open standard its widely used | Not that much compared to Binary. |
What is Serialization ? What are the Types of Serialization and their differences?
It is the process of converting an object to a form suitable for either making it persistent or tranportable.
Deserialization is the reverse of this and it converts the object from the serialized state to its original state.
Types:
1. Binary
2. XML
Differences:
Sno | Binary | XML |
1 | It preserves type fidelity , which is useful for preserving the state of the object between transportation and invocation. | It doesnt preserves type fidelity and hence state cant be maintained. |
2 | As it is the open standard its widely used | Not that much compared to Binary. |
What is an application domain?
Saturday, June 27, 2009
An application domain (often AppDomain) is a virtual process that serves to isolate an application. All objects created within the same application scope (in other words, anywhere along the sequence of object activations beginning with the application entry point) are created within the same application domain. Multiple application domains can exist in a single operating system process, making them a lightweight means of application isolation.
An OS process provides isolation by having a distinct memory address space. While this is effective, it is also expensive, and does not scale to the numbers required for large web servers. The Common Language Runtime, on the other hand, enforces application isolation by managing the memory use of code running within the application domain. This ensures that it does not access memory outside the boundaries of the domain. It is important to note that only type-safe code can be managed in this way (the runtime cannot guarantee isolation when unsafe code is loaded in an application domain).
What is an application domain?
An application domain (often AppDomain) is a virtual process that serves to isolate an application. All objects created within the same application scope (in other words, anywhere along the sequence of object activations beginning with the application entry point) are created within the same application domain. Multiple application domains can exist in a single operating system process, making them a lightweight means of application isolation.
An OS process provides isolation by having a distinct memory address space. While this is effective, it is also expensive, and does not scale to the numbers required for large web servers. The Common Language Runtime, on the other hand, enforces application isolation by managing the memory use of code running within the application domain. This ensures that it does not access memory outside the boundaries of the domain. It is important to note that only type-safe code can be managed in this way (the runtime cannot guarantee isolation when unsafe code is loaded in an application domain).
What is the difference between CCW and RCW ?
Sno | CCW | RCW |
1 | COM to .NET communication happens through COM Callable Wrapper | .NET to COM Communication happens through Remote Callable Wrappter |
What is the difference between CCW and RCW ?
Sno | CCW | RCW |
1 | COM to .NET communication happens through COM Callable Wrapper | .NET to COM Communication happens through Remote Callable Wrappter |
How to invoke a method at runtime using Reflection in c#?
You need to call “InvokeMember” method of Reflection to do this.
Let us see this in detail with an example,
1. Create a Class library program and paste the code below,
Reflection Source Program
=========================
using System;
using System.Collections.Generic;
using System.Text;
namespace Employee
{
public class EmployeeDetails
{
private int empid=1;
private string empname="Ram";
private float salary=100000;
public string displayEmployeeDetails()
{
return "Empoyee Id:" + empid + "
" + "Empoyee Name:" + empname + "
" + "Empoyee salary:" + salary + "
";
}
}
}
2. compile it.
3. then create a windows application project and paste the following code
Reflection Program to invoke the method
==================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Employee;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Assembly assembly = Assembly.LoadFrom("E:\\WebExperiments\\Employee\\Employee\\bin\\Debug\\Employee.dll");
foreach (Type type in assembly.GetTypes())
{
// Pick up a class
if (type.IsClass == true)
{
Console.WriteLine("...Found Class : {0}", type.FullName);
}
object ibaseObject = Activator.CreateInstance(type);
object result = null;
result = type.InvokeMember("displayEmployeeDetails",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
ibaseObject, null);
MessageBox.Show(result.ToString() );
}
}
}
}
4. add reference to the Employee dll
5. run the program and see the method invoked.
How to invoke a method at runtime using Reflection in c#?
You need to call “InvokeMember” method of Reflection to do this.
Let us see this in detail with an example,
1. Create a Class library program and paste the code below,
Reflection Source Program
=========================
using System;
using System.Collections.Generic;
using System.Text;
namespace Employee
{
public class EmployeeDetails
{
private int empid=1;
private string empname="Ram";
private float salary=100000;
public string displayEmployeeDetails()
{
return "Empoyee Id:" + empid + "
" + "Empoyee Name:" + empname + "
" + "Empoyee salary:" + salary + "
";
}
}
}
2. compile it.
3. then create a windows application project and paste the following code
Reflection Program to invoke the method
==================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Employee;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Assembly assembly = Assembly.LoadFrom("E:\\WebExperiments\\Employee\\Employee\\bin\\Debug\\Employee.dll");
foreach (Type type in assembly.GetTypes())
{
// Pick up a class
if (type.IsClass == true)
{
Console.WriteLine("...Found Class : {0}", type.FullName);
}
object ibaseObject = Activator.CreateInstance(type);
object result = null;
result = type.InvokeMember("displayEmployeeDetails",
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
ibaseObject, null);
MessageBox.Show(result.ToString() );
}
}
}
}
4. add reference to the Employee dll
5. run the program and see the method invoked.
Cystal Report Links
www.codeproject.com/KB/cs/CreatingCrystalReports.aspx
http://www.c-sharpcorner.com/Articles/ArticleListing.aspx?SectionID=1&SubSectionID=61
http://www.programmersheaven.com/download/44243/download.aspx
http://www.crystalreportsbook.com/Crystal_Reports_Net_Ch14_4.asp
Cystal Report Links
www.codeproject.com/KB/cs/CreatingCrystalReports.aspx
http://www.c-sharpcorner.com/Articles/ArticleListing.aspx?SectionID=1&SubSectionID=61
http://www.programmersheaven.com/download/44243/download.aspx
http://www.crystalreportsbook.com/Crystal_Reports_Net_Ch14_4.asp
mcse tutorial
Friday, June 26, 2009
www.intelligentedu.com/newly.../MCSE_Windows2000.html
www.mcsetutorialsonline.com
apex.vtc.com/mcse-bundle.php
www.velocityreviews.com/.../t237762-online-mcse-tutorial.html
www.learnthat.com/.../learn-430-windows_cp_mcse_practice_exam.htm
www.self-certify.com/mcse-tutorial.asp
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.skills_assessment&tid=bcee1d4b-e637-4ee6-989b-74acbe5efddb&cat=en_US_0d692642-c6e2-49ae-92c9-59a79e4fd247&lang=en&cr=US&sloc=&p=1
www.softwaretrainingtutorials.com/mcse-2003.php
.Net Tutorials
www.w3schools.com/ASPNET/default.asp
http://www.techtutorials.info/wbmsnet.html style="font-size: 11pt; font-family: Calibri">
www.programmingtutorials.com/vbnet.aspx
www.devarticles.com/c/b/VB.Net
what is autoeventwireup?
When the autoeventwireup page attribute is set to true page events are automatically called.
The disadvantage is that it expects page events in a predictable way , so you loose the flexibility of choosing your own event handler names.
where does a sharepoint webpart inherit from?
Microsoft.SharePoint.WebPartPages.WebPart
base class.
For creating a basic sharepoint webpart see this link,
http://msdn.microsoft.com/en-us/library/ms452873(loband).aspx
How do you relate an aspx page with its code behind page ?
Using the Page Directive.
<@page .. codefile="yourcsfile.aspx.cs" ...
What is web.config.? How many web.config files can be allowed to use in an application?
1.
The Web.Config file is the configuration file for
asp.net web application or a web site. prefix="o" ?>
2.
You can have as many Web.Config files as you want
, but there can be only one web.config file in a single folder.
What are asynchronous callbacks in .net?
How to call a user controls method from its parent?
Control declaration:
Public MyControls.SecureLoginControl objSecureLoginControl ;
When calling:
boolean b;
b=objSecureLoginControl.SecuredAuthentication();
or you can call like this also,
((SecureLoginControl)Panel1.FindControl("objSecureLoginControl")).SecuredAuthentication();
What is the difference between a custom control and a user control ?
Sno | User Control | Custom Control |
1 | Is a file with the .ascx extension | Is a file with the .dll extension |
2 | Can be only used with the application | Can be used in any number of applications |
3 | Language dependent. | They are language independent, a control created in c# can be used in vb.net |
4 | Can’t be added to Visual studio Toolbox | Can be added to Visual studio Toolbox |
5 | Inherits from Server controls and easy to create. | You have to develop from scratch , so comparatively difficult. |
6 | Generally used for static content | Used when dynamic content is required |
What are the differences between Trace and Debug?
Sno | Trace | Debug |
1 | Works in both Debug and Release mode | Works only in Debug mode. |
2 | Trace is enabled by default in visual studio | Debug is not enabled. You can manually do that. |
What are the differences between machine.config and web.config files?
Sno | Web.config | Machine.config |
1 | It is a config file for a single application. | It is a config file which is common for all the applications in a machine |
2 | It will be available in the application folder. | It is available in the Microsoft.NET\Framework\{version}\CONFIG Folder. |
3 | The settings in the web.config overrides that of Machine.config | Cant do. |
4 | Automatically installed when visual studio .net is installed | This is automatically created when you create an asp.ne website |
What are the differences between value and reference types
Sno | Value Types | Reference Types |
1 | They contain their data directly | They store a reference to their value’s memory |
2 | They are allocated for storage either in stack or inline in structure.. | They are allocated for storage in heap |
3 | can be built-in (implemented by the runtime), user-defined, or enumerations | self-describing types, pointer types, or interface types. |
microsoft tutorials
www.microsoft.com/education/tutorials.mspx
http://office.microsoft.com/en-us/training/default.aspx
www.officetutorials.com
http://databases.about.com/od/tutorials/Tutorials.htm
http://www.free-training-tutorial.com
http://www.learnthat.com
www.tutorialguide.net/microsoft
UML tutorials
www.sparxsystems.com.au/uml-tutorial.html
http://uml-tutorials.trireme.com/
www.tutorialspoint.com/uml/index.htm
www.freebookcentre.net/.../Free-Uml-Books-Download.html
http://courses.softlab.ntua.gr/softeng/Tutorials/UML-Use-Cases.pdf
mcse tutorial
www.intelligentedu.com/newly.../MCSE_Windows2000.html
www.mcsetutorialsonline.com
apex.vtc.com/mcse-bundle.php
www.velocityreviews.com/.../t237762-online-mcse-tutorial.html
www.learnthat.com/.../learn-430-windows_cp_mcse_practice_exam.htm
www.self-certify.com/mcse-tutorial.asp
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.skills_assessment&tid=bcee1d4b-e637-4ee6-989b-74acbe5efddb&cat=en_US_0d692642-c6e2-49ae-92c9-59a79e4fd247&lang=en&cr=US&sloc=&p=1
www.softwaretrainingtutorials.com/mcse-2003.php
.Net Tutorials
www.w3schools.com/ASPNET/default.asp
http://www.techtutorials.info/wbmsnet.html style="font-size: 11pt; font-family: Calibri">
www.programmingtutorials.com/vbnet.aspx
www.devarticles.com/c/b/VB.Net
what is autoeventwireup?
When the autoeventwireup page attribute is set to true page events are automatically called.
The disadvantage is that it expects page events in a predictable way , so you loose the flexibility of choosing your own event handler names.
where does a sharepoint webpart inherit from?
Microsoft.SharePoint.WebPartPages.WebPart
base class.
For creating a basic sharepoint webpart see this link,
http://msdn.microsoft.com/en-us/library/ms452873(loband).aspx
How do you relate an aspx page with its code behind page ?
Using the Page Directive.
<@page .. codefile="yourcsfile.aspx.cs" ...
What is web.config.? How many web.config files can be allowed to use in an application?
1.
The Web.Config file is the configuration file for
asp.net web application or a web site. prefix="o" ?>
2.
You can have as many Web.Config files as you want
, but there can be only one web.config file in a single folder.
What are asynchronous callbacks in .net?
How to call a user controls method from its parent?
Control declaration:
Public MyControls.SecureLoginControl objSecureLoginControl ;
When calling:
boolean b;
b=objSecureLoginControl.SecuredAuthentication();
or you can call like this also,
((SecureLoginControl)Panel1.FindControl("objSecureLoginControl")).SecuredAuthentication();
What is the difference between a custom control and a user control ?
Sno | User Control | Custom Control |
1 | Is a file with the .ascx extension | Is a file with the .dll extension |
2 | Can be only used with the application | Can be used in any number of applications |
3 | Language dependent. | They are language independent, a control created in c# can be used in vb.net |
4 | Can’t be added to Visual studio Toolbox | Can be added to Visual studio Toolbox |
5 | Inherits from Server controls and easy to create. | You have to develop from scratch , so comparatively difficult. |
6 | Generally used for static content | Used when dynamic content is required |
What are the differences between Trace and Debug?
Sno | Trace | Debug |
1 | Works in both Debug and Release mode | Works only in Debug mode. |
2 | Trace is enabled by default in visual studio | Debug is not enabled. You can manually do that. |
What are the differences between machine.config and web.config files?
Sno | Web.config | Machine.config |
1 | It is a config file for a single application. | It is a config file which is common for all the applications in a machine |
2 | It will be available in the application folder. | It is available in the Microsoft.NET\Framework\{version}\CONFIG Folder. |
3 | The settings in the web.config overrides that of Machine.config | Cant do. |
4 | Automatically installed when visual studio .net is installed | This is automatically created when you create an asp.ne website |
What are the differences between value and reference types
Sno | Value Types | Reference Types |
1 | They contain their data directly | They store a reference to their value’s memory |
2 | They are allocated for storage either in stack or inline in structure.. | They are allocated for storage in heap |
3 | can be built-in (implemented by the runtime), user-defined, or enumerations | self-describing types, pointer types, or interface types. |
microsoft tutorials
www.microsoft.com/education/tutorials.mspx
http://office.microsoft.com/en-us/training/default.aspx
www.officetutorials.com
http://databases.about.com/od/tutorials/Tutorials.htm
http://www.free-training-tutorial.com
http://www.learnthat.com
www.tutorialguide.net/microsoft
UML tutorials
www.sparxsystems.com.au/uml-tutorial.html
http://uml-tutorials.trireme.com/
www.tutorialspoint.com/uml/index.htm
www.freebookcentre.net/.../Free-Uml-Books-Download.html
http://courses.softlab.ntua.gr/softeng/Tutorials/UML-Use-Cases.pdf
Free domain from Microsoft with lot of features
Free domain from Microsoft with lot of features. Get benefitted from it.
Free domain from Microsoft with lot of features
Free domain from Microsoft with lot of features
Free domain from Microsoft with lot of features. Get benefitted from it.
Free domain from Microsoft with lot of features
What should be done to make a session cookieless
Thursday, June 25, 2009
set the cookieless attribute to 'false', as
<sessionstate timeout='20' cookieless='false' mode='InProc'>
What should be done to make a session cookieless
set the cookieless attribute to 'false', as
<sessionstate timeout='20' cookieless='false' mode='InProc'>
What should be done to make a session cookieless
how will u check whether the user is supportig cookies?
If you are able to read it back then , its accepting else not.
how will u check whether the user is supportig cookies?
If you are able to read it back then , its accepting else not.
how will u check whether the user is supportig cookies?
If you are able to read it back then , its accepting else not.
what does '()' denote in the object creation statement
It denotes the constructor.
what does '()' denote in the object creation statement
It denotes the constructor.
what does '()' denote in the object creation statement
It denotes the constructor.
How to call a base class constructor from a derived class?
using System;
using System.Collections.Generic;
using System.Text;
namespace OOPTest7
{
class A
{
public A()
{
Console.Out.Write("base A");
}
public A(string s)
{
Console.Out.Write(s);
}
}
class B : A
{
public B() : base("base cons called from Derived")
{
Console.Out.Write("B");
}
}
class Program
{
static void Main(string[] args)
{
B b= new B();
Console.In.Read();
}
}
}
How to call a base class constructor from a derived class?
using System;
using System.Collections.Generic;
using System.Text;
namespace OOPTest7
{
class A
{
public A()
{
Console.Out.Write("base A");
}
public A(string s)
{
Console.Out.Write(s);
}
}
class B : A
{
public B() : base("base cons called from Derived")
{
Console.Out.Write("B");
}
}
class Program
{
static void Main(string[] args)
{
B b= new B();
Console.In.Read();
}
}
}
How to call a base class constructor from a derived class?
using System;
using System.Collections.Generic;
using System.Text;
namespace OOPTest7
{
class A
{
public A()
{
Console.Out.Write("base A");
}
public A(string s)
{
Console.Out.Write(s);
}
}
class B : A
{
public B() : base("base cons called from Derived")
{
Console.Out.Write("B");
}
}
class Program
{
static void Main(string[] args)
{
B b= new B();
Console.In.Read();
}
}
}
interface ,the class which implemented it and its object, with interface in left hand side during creation
can is the following allowed? Will that have all the methods of IA apart from that of interface I?
I a = new IA();
Yes. always the base class or interface can contain derived class, but it will have
only those of the base. So it will not have members of IA which are not from interface I.
using System;
using System.Collections.Generic;
using System.Text;
namespace OOPTest6
{
interface I
{
void a();
}
class IA : I
{
public void a()
{
Console.Out.Write("a");
}
public void nonintfacemeth()
{
Console.Out.Write("nonintfacemeth");
}
}
class Program
{
static void Main(string[] args)
{
I i = new IA();
i.a();
}
}
}
interface ,the class which implemented it and its object, with interface in left hand side during creation
can is the following allowed? Will that have all the methods of IA apart from that of interface I?
I a = new IA();
Yes. always the base class or interface can contain derived class, but it will have
only those of the base. So it will not have members of IA which are not from interface I.
using System;
using System.Collections.Generic;
using System.Text;
namespace OOPTest6
{
interface I
{
void a();
}
class IA : I
{
public void a()
{
Console.Out.Write("a");
}
public void nonintfacemeth()
{
Console.Out.Write("nonintfacemeth");
}
}
class Program
{
static void Main(string[] args)
{
I i = new IA();
i.a();
}
}
}
interface ,the class which implemented it and its object, with interface in left hand side during creation
can is the following allowed? Will that have all the methods of IA apart from that of interface I?
I a = new IA();
Yes. always the base class or interface can contain derived class, but it will have
only those of the base. So it will not have members of IA which are not from interface I.
using System;
using System.Collections.Generic;
using System.Text;
namespace OOPTest6
{
interface I
{
void a();
}
class IA : I
{
public void a()
{
Console.Out.Write("a");
}
public void nonintfacemeth()
{
Console.Out.Write("nonintfacemeth");
}
}
class Program
{
static void Main(string[] args)
{
I i = new IA();
i.a();
}
}
}
If A is the base class and B inherits B and C inherits B and an object is created for C , whats order of constructor
the constructor being called?
A then B then C.
using System;
using System.Collections.Generic;
using System.Text;
namespace OopTest5
{
class A
{
public A()
{
Console.Out.Write("A");
}
}
class B : A
{
public B()
{
Console.Out.Write("B");
}
}
class C : B
{
public C()
{
Console.Out.Write("C");
}
}
class Program
{
static void Main(string[] args)
{
C c = new C();
Console.In.Read();
}
}
}
If A is the base class and B inherits B and C inherits B and an object is created for C , whats order of constructor
the constructor being called?
A then B then C.
using System;
using System.Collections.Generic;
using System.Text;
namespace OopTest5
{
class A
{
public A()
{
Console.Out.Write("A");
}
}
class B : A
{
public B()
{
Console.Out.Write("B");
}
}
class C : B
{
public C()
{
Console.Out.Write("C");
}
}
class Program
{
static void Main(string[] args)
{
C c = new C();
Console.In.Read();
}
}
}
If A is the base class and B inherits B and C inherits B and an object is created for C , whats order of constructor
the constructor being called?
A then B then C.
using System;
using System.Collections.Generic;
using System.Text;
namespace OopTest5
{
class A
{
public A()
{
Console.Out.Write("A");
}
}
class B : A
{
public B()
{
Console.Out.Write("B");
}
}
class C : B
{
public C()
{
Console.Out.Write("C");
}
}
class Program
{
static void Main(string[] args)
{
C c = new C();
Console.In.Read();
}
}
}
how to implement a pure virtual function in c#?
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
public override void a()
{
Console.Out.Write("a");
}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
UsesabTest mn = new UsesabTest();
mn.a();
}
}
}
Can we leave a virtual function in an abstract class without implementing in the derived class
No.
Instead you can use abstract function which is also called as a pure virtual function.
abstract class abTest
{
public abstract void a();
}
Can we leave a virtual function in an abstract class without implementing in the derived class ?
No. It will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
//public override void a()
//{
// Console.Out.Write("a");
//}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
}
}
}
Does C# (.NET) support partial implementation?
No.
the following program will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OPPTest3
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}
Can we leave a virtual function in an abstract class without implementing in the derived class
No.
Instead you can use abstract function which is also called as a pure virtual function.
abstract class abTest
{
public abstract void a();
}
Can we leave a virtual function in an abstract class without implementing in the derived class ?
No. It will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
//public override void a()
//{
// Console.Out.Write("a");
//}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
}
}
}
Does C# (.NET) support partial implementation?
No.
the following program will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OPPTest3
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}
Can we leave a virtual function in an abstract class without implementing in the derived class
No.
Instead you can use abstract function which is also called as a pure virtual function.
abstract class abTest
{
public abstract void a();
}
Can we leave a virtual function in an abstract class without implementing in the derived class ?
No. It will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
//public override void a()
//{
// Console.Out.Write("a");
//}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
}
}
}
Does C# (.NET) support partial implementation?
No.
the following program will throw an error.
using System;
using System.Collections.Generic;
using System.Text;
namespace OPPTest3
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}
Class implementing Interface
using System.Collections.Generic;
using System.Text;
namespace OppTest2
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
public void y()
{
Console.Out.Write("test y");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}
Can a base class contain its derived class?
Yes. But the reverse is not possible.
using System;
using System.Collections.Generic;
using System.Text;
namespace OppsTest
{
class A
{
int i = 1;
public A()
{
}
public void testa()
{
Console.Out.Write(i);
}
}
class B : A
{
int j = 3;
public B()
{
}
public void testb()
{
Console.Out.Write(j);
}
}
class Program
{
static void Main(string[] args)
{
A a = new B();
a.testa();
Console.In.Read();
}
}
}
Class implementing Interface
using System.Collections.Generic;
using System.Text;
namespace OppTest2
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
public void y()
{
Console.Out.Write("test y");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}
Can a base class contain its derived class?
Yes. But the reverse is not possible.
using System;
using System.Collections.Generic;
using System.Text;
namespace OppsTest
{
class A
{
int i = 1;
public A()
{
}
public void testa()
{
Console.Out.Write(i);
}
}
class B : A
{
int j = 3;
public B()
{
}
public void testb()
{
Console.Out.Write(j);
}
}
class Program
{
static void Main(string[] args)
{
A a = new B();
a.testa();
Console.In.Read();
}
}
}
Class implementing Interface
using System.Collections.Generic;
using System.Text;
namespace OppTest2
{
interface IA
{
void x();
void y();
}
class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
public void y()
{
Console.Out.Write("test y");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}
Can a base class contain its derived class?
Yes. But the reverse is not possible.
using System;
using System.Collections.Generic;
using System.Text;
namespace OppsTest
{
class A
{
int i = 1;
public A()
{
}
public void testa()
{
Console.Out.Write(i);
}
}
class B : A
{
int j = 3;
public B()
{
}
public void testb()
{
Console.Out.Write(j);
}
}
class Program
{
static void Main(string[] args)
{
A a = new B();
a.testa();
Console.In.Read();
}
}
}
how to implement a pure virtual function in c#?
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
public override void a()
{
Console.Out.Write("a");
}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
UsesabTest mn = new UsesabTest();
mn.a();
}
}
}
how to implement a pure virtual function in c#?
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
public override void a()
{
Console.Out.Write("a");
}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
UsesabTest mn = new UsesabTest();
mn.a();
}
}
}
how to implement a pure virtual function in c#?
using System;
using System.Collections.Generic;
using System.Text;
namespace OppTest4
{
abstract class abTest
{
public abstract void a();
}
class UsesabTest : abTest
{
public override void a()
{
Console.Out.Write("a");
}
public void x()
{
Console.Out.Write("x");
}
}
class Program
{
static void Main(string[] args)
{
UsesabTest mn = new UsesabTest();
mn.a();
}
}
}
FxCop – Part III (A detailed explanation over Project)
In the Part I we saw the introduction to FxCop and in Part II we saw about the startup usage of FxCop. In this Part III we are going to see in detail about FxCop Project and its features.
Here we dived the explanations over the Project into 2, they are:
· Basics of Project
· Advanced features of Project
Basics of Project:
In this we will see the basics of FxCop Project which needs little explanation. The topics we are going to cover here are:
1. Creating a new project
2. Open an existing project
3. Saving project
4. Opening Recent Projects
5. Saving Reports
6. Importing Reports
7. Adding Targets
8. Adding Rules
9. Analyzing a Project
10. Viewing Analysis Summary
1. Creating a new Project:
To create a new project,
Click File > New Project.
2. Open an existing project
To open an exiting project,
· File > Open Project
· Select the project file you want to open from the location you stored it or the location in which it is available.
· Click Open button.
3. Saving project
You can save the project in 2 ways, as follows,
i) When you are saving it for the first time
ii) When you are saving one more copy of the project.
a) When you are saving it for the first time
· Click File > Save Project or Ctrl S
· Select the path where you want to save it
· Enter the name of the project you want to save in
· Click Save
b) When you are saving one more copy of the project
· Click File > Save Project as
· Select the path where you want to save it
· Enter the name of the project you want to save in
· Click Save
4. Opening Recent Projects
To open Opening Recent Projects,
a) Click File > Recent Projects
b) Select the desired project
5. Saving Reports
To save reports,
· Click File > Save Report as
· Select the path where you want to save it
· Enter the name of the Report you want to save in
· Click Save
6. Importing Reports
To Import Reports,
· Click File > Import Reports or Ctrl I
· Select the Report file you want to open from the location you stored it or the location in which it is available.
· Click Open button
7. Adding Targets
To add Target,
· Project > Add Targets.
· Select the desired assembly you want to analyze(it can either be a dll or an exe).
8. Adding Rules
To Add Rules,
· Project > Add Rules.
· Select the desired Rules dll from the location you are having the rules.
9. Analyzing a Project
To analyze a project, its given in detail in the earlier chapters. Anyhow its given here once more for continuity or completeness of the topic.
· Select the desired assembly you want to analyze (it can either be a .dll or an .exe).
· For example, I am selecting here a .net application (Which was downloaded from internet)
· If you have selected multiple assemblies then select any one of them (the one you want to analyze first) and then click Project > Analyze or press F5 or Click Analyze from toolbar.
· Analyzing with introspection Engine dialog box will appear when the analysis is under process.
· Then it will display list of messages in the right pane.
10. Viewing Analysis Summary
To view Analysis Summary report,
· Click Project > Analysis summary
· Analysis summary window will appear.
· Click ok to close the window.
Advanced features of Project:
In this we will Advanced features of FxCop Project which needs some explanation. The topics we are going to cover here are:
1. General Project settings
2. Saving and Compression settings
3. Spelling and Analysis settings
4. Preferences Settings
5. Font and colors settings
6. Analysis Engine settings
1. General Project settings
For doing General Project settings,
· Click Project > Options
· Select General tab
Here you can do the things like:
(1) Changing Project name
(2) Changing Report style sheet path
(3) Save messages settings for Project and Reports
2. Saving and Compression settings
For doing this,
· Click Project > Options
· Select Saving and Compression tab
Here you can do the things like:
(1) Project Save settings
(2) Project File name Rule settings
(3) Compression settings
3. Spelling and Analysis settings
For doing this,
· Click Project > Options
· Select Spelling and Analysis tab
Here you can do the things like:
(1) Multithreading settings
(2) GAC settings
(3) Spelling and analysis settings
4. Preferences Settings
For doing this,
· Click Tools > Settings
· Select Preferences tab
Here you can do the things like:
(1) General preference settings like checking for updates in startup,etc
(2) Filtering messages
(3) Launching in source code editor
(4) Command line settings
5. Font and colors settings
For doing this,
· Click Tools > Settings
· Select Font and colors tab
As the name implies, it does the font and color related settings.
6. Analysis Engine settings
For doing this,
· Click Tools > Settings
· Select Analysis Engine tab
Here you can do the things like:
(1) Engine related settings
(2) Some more advanced settings.