Pages

Showing posts with label .Net Framework. Show all posts
Showing posts with label .Net Framework. Show all posts

Tuesday, September 20, 2011

Types of Design Patterns

Hi Frnds
There are 23 design patterns that are used in the application development.These are divied into thre sub groups: Creational,Structural and Behavioral.

Creational

Creational patterns is used when object construction and referencing are the concerns.In short,the responsibility of instantiating instances of objects from the client, by which keeping the code loosely coupled and the responsibility of creating complex objects in one place having the Single Responsibility and
Separation of Concerns principles.
The patterns which comes  in the Creational group:
Abstract Factory: Provides an interface to create families of related objects.
Factory: Enables a class to delegate the responsibility of creating a valid object.
Builder: Enables various versions of an object to be constructed by separating the construction
for the object itself.
Prototype: Allows classes to be copied or cloned from a prototype instance rather than creating
new instances.
Singleton: Enables a class to be instantiated once with a single global point of access to it.

Structural

Structural patterns is used when the composition and relationships of objects to fulfill the needs of
larger systems.
The patterns which comes  in the Structural group:
Adapter: Enables classes of incompatible interfaces to be used together.
Bridge: Separates an abstraction from its implementation, allowing implementations and
abstractions to vary independently of one another.
Composite: Allows a group of objects representing hierarchies to be treated in the same way
as a single instance of an object.
Decorator: Can dynamically surround a class and extend its behavior.
Facade: Provides a simple interface and controls access to a series of complicated interfaces
and subsystems.
Flyweight: Provides a way to share data among many small classes in an efficient manner.
Proxy: Provides a placeholder to a more complex class that is costly to instantiate.

Behavioral

Behavioral patterns is used when the communication between objects in terms of responsibility and
algorithms. The patterns in this group encapsulate complex behavior and abstract it away from the
flow of control of a system, thus enabling complex systems to be easily understood and maintained.
The patterns which comes  in the Behavioral group:
Chain of Responsibility: Allows commands to be chained together dynamically to handle a
request.
Command: Encapsulates a method as an object and separates the execution of a command
from its invoker.
Interpreter: Specifies how to evaluate sentences in a language.
Iterator: Provides a way to navigate a collection in a formalized manner.
Mediator: Defines an object that allows communication between two other objects without
them knowing about one another.
Memento: Allows you to restore an object to its previous state.
Observer: Defines the way one or more classes can be alerted to a change in another class.
State: Allows an object to alter its behavior by delegating to a separate and changeable state
object.
Strategy: Enables an algorithm to be encapsulated within a class and switched at run time to
alter an object’s behavior.
Template Method: Defines the control of flow of an algorithm but allows subclasses to override
or implement execution steps.
Visitor: Enables new functionality to be performed on a class without affecting its structure.

These all are the patterns which are used in the aplication development.
Happy Coding :)

Wednesday, September 14, 2011

Unmanaged vs. Managed Code

Unmanaged executable files are binary images of x86 code loaded into memory. The role of the operating system in this case is to load the application into memory and let it run. Although there are some protections regarding memory management and I/O ports, the operating system does not have any idea what the application is doing.

By contrast, managed code is under full control of the operating system. At any point in time, the operating system can stop running the CPU and investigate the runtime state. It can also insert exception handling, array bounds and indexes, traps, garbage collection hooks, and other things. In this way, it mitigates a whole class of security concerns and typical programming errors. All programming languages that support the .NET Framework produce managed code. There are currently over 30 such languages. Several are provided by Microsoft (C#, Visual Basic .NET, managed C++, J#, JScript .NET), while others are developed by third parties (everything from COBOL to Pascal).

Sunday, September 11, 2011

Basic Simple Programs for Interview

Hi Friends this time I am sharing you a very simple basic programs that generally asked at the time of interview. I used to asked it some times a very very simple programs ..we know that we can make it out those program but in interview time if you know how to do that then you can make it out very easyly and make a face that you are thinking about it ;) .. but you know already . and write it after some moments . ;) So just take a look before the interview ..!! All the best friends..!! Prog1:Retrun Vowel of Not. Solution: ======
public bool CheckVowel(object sender,KeyEventArgs e)
{
    if(e.KeyCode ==Keys.A||e.KeyCode ==Keys.E||e.KeyCode ==Keys.I||e.KeyCode ==Keys.O||e.KeyCode ==Keys.U)
    {    
    return true;
    }
    else
    return false;
}
Prog 2: Even Or Odd Solution: ======
public string EvenOrOdd( int Num)
{
    if(num%2 ==0)
    retrun "evenNumber";
    else
    return "OddNumber"
}
Prog3:PrimeNumber Soultion: ======
public string PrimeOrNot(int num)
{
    int i = 0;
    for (i = 3; i < num; i++)
    {
        if (num % i == 0)
        {
            Console.WriteLine("{0} is not a prime number", num);
            break;
        }
    }
    if (i == num)
    {
        Console.Writeline("{0} is a prime Number", num);
    }
}
Prog4:Fibonacci Series Solution: =======
public void FibonacciSeries(int number)
{
    int f_0 = 0;
    int f_1 = 1;
    int sum;
    Console.Write("{0} {1} ", f_0, f_1);
    for (int i = 2; i < number; i++)
    {
        sum = f_0 + f_1;
        f_0 = f_1;
        f_1 = sum;
        int value = f_0 + f_1;
        Console.Write("{0} ", value);
    }
}
Prog5: Factorial Solution: =======
public int Factorial(int number)
{
    int value = 1;
    for (int i = 1; i <= number; i++)
    {
        value = value * i;
    }
    return value;
}
Prog:6 Permutation (nPr) Solution: ====== Refrence Solution 5;
public double Permutation(int n, int r)
{
    double nPr = Factorial(n) / Factorial(n - r);
    return nPr;
}
 
Prog:7 Combination(nCr) Solution: ====== Refrence Solution 5;
public double Combination(int n , int r)
{
double nCr = Factorial(n)/Factorial(r)*(Factorial(n-r);
return nCr;
}
Prog8 : Add two numbers without using the plus operator Solution: ======
public int Add (int x , int y )
{
    return x-(-y);
}    
Prog9: Multiply two numbers without usering * operator Solution: =======
public int MulWithOutStarOperator( int x ,int y)
{
    for(int z= 1 ; z<=y ; z++)
    {
        int value = value +x;
    }
    return value;
} 
Prog:10 String Reverse Solution: =======
public string ReverseString(string str)
{
    int strLenght = str.Lenght;
    char strArray[] = new char[strLength];
    for ( int i = 0 ; i

Prog:11 Return multiple values from a function

Solution:
========

public int Add(int a,int b,out int c)
{
     c=a+1;
     return a+b;
}
Description : --------------- when we call the Add method we will get the sum of the a and b and can also use the value of c like int d=0; int e= Add(2,3,d) ; then the value of e will be 5 and the value of d will be 3.

Saturday, September 10, 2011

Lazy Loading in C# 4.0(Object On Demand)

Object on Demand is also called as Lazy loading pattern ,Lazy loading  delay the initialization of object. This is a new feature of C# 4.0 its can be used when we are working with large objects when its not in use. This article will explain you about "Lazy" class.
Suppose Candidate class and EducationProfile class . One candidate can have more than one EducationProfile (like: Bachelors (BBA) ,Master(MBA)). if you want to show the EducationProfile which the respective Candidate.You need to load EducationProfiles associated with that Candidate. If  You are loading a Education Profile it with the respective candidate . you need to initialize a Candidate object and that is suppose to be huge .
For avoiding the situation you can use the Lazy Loading Pattern. Loading of EdutioanProfile will only happen when you will use EducationProfile list . and this will make sure fast action  in comparison to the normal one and performance will also increase.
Explaining example of Candidate and  EducationProfile relationship by Lazy loading:
First we need to create ay classes of Candidate and EducationProfile.

public class EducationProfile
{
    public int Id { get; set; }
    public string Digree { get; set; }
    public DateTime PassingYear { get; set; }
}

//Hope this will give you a little reference of lazy loading 

public class Candiate
{
    public string Name { get; set; }
    public int EducationProfileId { get; set; }
    public List GetAllEducationProfile()
    {
        return educationProileList.value;
    }

    Lazy> educationProileList;

    public Candiate(string name, int id)
    {
        //Initializing Candiate Object
        Name = name;
        EducationProfileId = id;
        educationProileList = new Lazy>(() => { return GetEducationProfileList(id); });
        //Initialization done
    }

    private List GetEducationProfileList(int id)
    {
        //Loading EducationProiles
        List list = new List();
        Parallel.For(100, 110, (int i) =>
        {
            EducationProile educationprofile = new EducationProile();
            educationprofile.Id = i;
            list.Add(educationprofile);
        });
        return list;
    }
}

In the constructor of Candidate class, properties are initializing and declaring educationProileList object, which is generic List of educationProile and filled by GetEducationProfileList method. This method will only call when educationProileList object will be use. Below is main method which shows behavior of lazy loading:
public static void Main(string[] args) 
{
    Candidate candidate = new Candidate("AnyName", 1);
    foreach(EducationProile eduProfile in candiate.GetAllEducationProfile())
    // it will actually load accounts, ie. lazy loading
    Console.WriteLine("Id:{0}",eduProfile.Id);
    Console.Read();
}