Difference
between Events and Delegates
S.No
|
Events
|
Delegates
|
1
|
Event
can be used in an interface definition
|
Delegate
cannot be used in an interface definition
|
2
|
Event
can only be invoked from the class that declares it
|
Delegates
can be invoked from child classes and clients.
|
3
|
Event
comes with its pair of accessors
i.e Add and Remove. An event is always assigned and unassigned
with a += and -= operator.
|
There
is no pair of accessors concept in delegates.
|
4
|
Event
has a restrictive signature and must always be of the form Event
(object source, EventArgs
args)
|
Delegates
do not have restrictive signature as
like events
|
Difference
between Class and Object
S.No
|
Class
|
Object
|
1
|
It
is a datatype that contains the programming logic.
|
It
is a chunk of memory that implements the class logic.
|
2
|
Class
is visible in the source code and resides in hard disk.
|
Object
is in the RAM and not visible in source code.
|
3
|
Class
is like a template or blueprint of the object. It implements
reusability,encapsulation, inheritance
|
It
is the real world implementation of the class. Each object has its
own copy of data.
|
4
|
Example:Button
is a class with properties like Text,BackColor,
events like click, methods like Focus |
Example:
Button1,
Button2 are the objects of Button class.
|
5
|
We
can create subclasses
|
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.
|
Private
constructor is called after the instance of the class is created.
|
2
|
Static
constructor will be called first time when the class is
referenced.Static constructor is used to initialize static members
of the class.
|
Static
members will not be initialized either by private or public
constructor.
|
3
|
The
static constructor will only be executed once.
|
The
private constructor will be executed each time it is called.
|
Difference
between properties and methods
S.No
|
Properties
|
Methods
|
1
|
Properties
are used to represent data
|
Methods
are used to performs actions
|
2
|
Properties
are created by using getter and setter i.e., get{} and set{}
|
Methods
create like public void method1(parameter list here)
|
Difference
between Singleton Pattern and static class
S.No
|
Singleton
Pattern
|
static
class
|
Singleton
pattern maintains single instance.
|
We
cannot create instance for static class.
|
|
2
|
A
singleton can extend classes and implement interfaces.
|
A
static class cannot .
Note:
It can extend classes, but it does not inherit their instance
members.
|
3
|
A
singleton can be initialized lazily or asynchronously.
|
A
static class is generally initialized when it is first loaded,
leading to potential class loader issues.
|
4
|
Singletons
can be handled polymorphically without forcing their users to
assume that there is only one instance.
|
static
class cannot be handled polymorphically.
|
5
|
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.
|
Static
are always just shared and have no instance but multiple
references.
|
6
|
We
can pass singleton object as parameter
|
We
cannot pass parameter in static class
|
7
|
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.
|
Static
classes once defined could not accomodate any future design
changes as by design static classes are rigid and cannot be
extended.
|
No comments:
Post a Comment