Docstoc

OOPs Difference FAQs-2

Document Sample
OOPs Difference FAQs-2 Powered By Docstoc
					Difference between Events and Delegates

  S.No    Events                                Delegates
  1       Event can be used in an               Delegate cannot be used in an
          interface definition                  interface definition

  2       Event can only be invoked from        Delegates can be invoked from child
          the class that declares it            classes and clients.

  3       Event comes with its pair of          There is no pair of accessors concept
          accessors i.e Add and Remove.         in delegates.
          An event is always assigned and
          unassigned with a += and -=
          operator.
  4       Event has a restrictive signature     Delegates do not have restrictive
          and must always be of the form
                                                signature as like events
          Event (object source, EventArgs
          args)

Difference between Class and Object

  S.No     Class                                    Object
  1        It is a datatype that contains the       It is a chunk of memory that
           programming logic.                       implements the class logic.
  2        Class is visible in the source code      Object is in the RAM and not
           and resides in hard disk.                visible in source code.
  3        Class is like a template or blueprint    It is the real world implementation
           of the object. It implements             of the class. Each object has its
           reusability,encapsulation,               own copy of data.
           inheritance
  4        Example:Button is a class with           Example: Button1, Button2 are the
           properties like Text,BackColor,          objects of Button class.
           events like click, methods like
           Focus
  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         Private constructor is called after the
            before the first instance is           instance of the class is created.
            created. i.e. global initializer.
 2          Static constructor will be called      Static members will not be initialized
            first time when the class is           either by private or public
            referenced.Static constructor is       constructor.
            used to initialize static members
            of the class.
 3          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     Properties                            Methods
    1        Properties are used to represent      Methods are used to performs actions
             data
    2        Properties are created by using       Methods create like public void
             getter and setter i.e., get{} and     method1(parameter list here)
             set{}


Difference between Singleton Pattern and a static class

S.No       Singleton Pattern                       static class

           Singleton pattern maintains single      We cannot create instance for static
           instance.                               class.
2          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.
3          A singleton can be initialized lazily   A static class is generally initialized
           or asynchronously.                      when it is first loaded, leading to
                                                   potential class loader issues.
4          Singletons can be handled               static class cannot be handled
           polymorphically without forcing         polymorphically.
           their users to assume that there is
           only one instance.
5          Singleton Class can have value          Static are always just shared and have
           when Class object instantiated          no instance but multiple references.
           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.
6          We can pass singleton object as         We cannot pass parameter in static
           parameter                               class
7          Singleton provides flexibility and      Static classes once defined could not
           also provides sort of a mechanism       accomodate any future design
           to control object creation based on     changes as by design static classes
           various requirements. They can be       are rigid and cannot be extended.
           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.

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:15
posted:7/10/2012
language:English
pages:3
Description: This provides a list of OOPs FAQs-2 which are of "Difference between" kind