Friday, July 28, 2006

 

Naming Guide Lines

Pascal case The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. You can use Pascal case for identifiers of three or more characters. For example:BackColor Camel case The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. For example:backColor Uppercase All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or fewer letters. For example:System.IO System.Web.UI In C#, mostly Pascal case is used except for method parameter and local veriables. MSDN Naming guidelines

 

How to create Singleton

Singleton is a 'creational pattern' which is used when 'only' one instance of the object is required for the entire client process...Singleton enforces this by creating a private/protected default constructor... here is the whole process Your singleton object should have the following:

class MySingleton{

private static MySingleton obj;

private MySingleton(){};

public static MySigleton GetInstance()

{

if (obj == null) obj = new MySingleton();

return obj;

}

//all other functions go here.. these functions have to be static

}

From the client, a sigleton is used like the following:

public static void main()

{

//Since MySingleton has a private constructor, it can not be instantiated like a regular class. The

following code throws an error

//MySingleton 0 = new MySingleton(); //throws errror

MySingleton obj1 = MySigleton.GetInstance(); // since this is first call, an object gets created in the GetInstance function and gets added to the class global variable of obj

obj1.function1();

obj1.function2();

//Now later when the user tried to create a new object of MySigleton, the same object is returned

MySingleton obj2 = MySigleton.GetInstance(); //returns the same object created in the first call.

}


 

Design Patterns

  1. Singleton
  2. Factory
  3. Abstract
  4. Builder
  5. Prototype
  1. Adapter
  2. Bridge
  3. Composite
  4. Decorator
  5. Facade
  6. Flyweight
  7. Proxy
  1. Chain Of Responsibility
  2. Command
  3. Interpreter
  4. Iterator
  5. Mediator
  6. Memento
  7. Observer
  8. State
  9. Strategy
  10. Template Method
  11. Visitor

Tuesday, July 11, 2006

 

what is the use of 'new' in funciton signature

class BaseClass { public int Add(int a, int b) { return a+b; } } class DerivedClass:BaseClass { public int new Add(int a, int b) { return a+b; } } Note: When the object of DerivedClass is used to access Add function, which of the functions is called ? It would be the one of DerivedClass. This is same even if "new" is used or not. Then what is the use of "new" ? Without "new" complier throws an error of ambiguity. With "new", compiler understands that the programmer knows about the ambiguity and still want the function with the signature to exist in the derived class too.

This page is powered by Blogger. Isn't yours?