Sunteți pe pagina 1din 3

Difference between Events and Delegates S.

No
1 2 3

Events
Event can be used in an interface definition Event can only be invoked from the class that declares it Event comes with its pair of accessors i.e Add and Remove. An event is always assigned and unassigned with a += and -= operator. Event has a restrictive signature and must always be of the form Event (object source, EventArgs args)

Delegates
Delegate cannot be used in an interface definition Delegates can be invoked from child classes and clients. There is no pair of accessors concept in delegates.

Delegates do not have restrictive signature as like events

Difference between Class and Object S.No


1 2 3

Class
It is a datatype that contains the programming logic. Class is visible in the source code and resides in hard disk. Class is like a template or blueprint of the object. It implements reusability,encapsulation, inheritance Example:Button is a class with properties like Text,BackColor, events like click, methods like Focus We can create subclasses

Object
It is a chunk of memory that implements the class logic. Object is in the RAM and not visible in source code. It is the real world implementation of the class. Each object has its own copy of data.

Example: Button1, Button2 are the


objects of Button class. We cannot create sub-objects

Difference between Private and Static Constructor S.No Static constructor Private constructor
1 A static constructor is called before the first instance is created. i.e. global initializer. Static constructor will be called first time when the class is referenced.Static constructor is used to initialize static members of the class. Private constructor is called after the instance of the class is created. Static members will not be initialized either by private or public constructor.

The static constructor will only be The private constructor will be executed once. executed each time it is called.

Difference between properties and methods S.No


1 2

Properties
Properties are used to represent data Properties are created by using getter and setter i.e., get{} and set{}

Methods
Methods are used to performs actions Methods create like public void method1(parameter list here)

Difference between Singleton Pattern and a static class S.No Singleton Pattern
Singleton pattern maintains single instance. 2

static class
We cannot create instance for static class.

A singleton can extend classes and A static class cannot . implement interfaces. Note: It can extend classes, but it does not inherit their instance members. A singleton can be initialized lazily or asynchronously. Singletons can be handled polymorphically without forcing their users to assume that there is only one instance. Singleton Class can have value when Class object instantiated between server and client, such a way if three client want to have a shared data between them Singleton can be used.Thats why singleton class can be used for state mangement in stateless scenarios like shopping cart scenario. We can pass singleton object as parameter Singleton provides flexibility and also provides sort of a mechanism to control object creation based on various requirements. They can be extended as well if need arises. In other words we are not always tied to a particular implementation. With Singleton we have the flexibility to make changes as when situation demands. A static class is generally initialized when it is first loaded, leading to potential class loader issues. static class cannot be handled polymorphically.

Static are always just shared and have no instance but multiple references.

6 7

We cannot pass parameter in static class Static classes once defined could not accomodate any future design changes as by design static classes are rigid and cannot be extended.

S-ar putea să vă placă și