Monday, 3 February 2014

Abstract, Sealed, Static, Partial - Classes

Class Types:
1) Abstract class
2) Sealed Class
3) Static Class
4) Partial Class
-----------------------------------------
A-- Abstract
S-- Sealed
S--Static
ASS is order by name
Keyword
Can be instantiated(object)
Can be inherited
Abstract
 NO
 YES
Sealed
YES
 NO
Static
NO
NO

Abstract Class
  1. It only represents the base class and thus has be inherited for its use.
  2. Object can NOT be created. can NOT be instantiated.
  3. Abstract class and methods can NOT be sealed ( class which can not be inherited).
  4. Abstract methods can NOT be private.
  5. Abstract methods can NOT be virtual ( by default they are virtual).
  6. Abstract class and methods can NOT be static.
  7. Abstract method definition can be given only inside a Abstract class. In non abstract class no abstract method can be defined.
  8. Can have either abstract method or non-abstract methods.
  9. Abstract method do not have any implementation of methods but has to be provided the same in the derived class.
  10. Abstract class may contain NO abstract method at all. 
  11. Abstract methods has to be override in derived class. 
  12. Derived class has to implement all abstract methods of abstract class.

abstract class absClass
{
   public abstract int abstractMethod(int Num1, int Num2);
}

 public override int abstractMethod(int Num1, int Num2)
{
    return Num1 * Num2;
 }

Sealed Class
  1. Restrict inheritance. can NOT be inherited. Its just to take away the inheritance feature.
  2. Structs are sealed in nature.
  3. NO restriction on object creation. sealed class can be instantiated.
  4. If you make a sealed a method / property that overrides a virtual method /property  it will get prevented from further overriding.
  5. Best use of sealed class is when your sealed class has static members (How?).
class X
{
  protected virtual void F() { Console.WriteLine("X.F"); }
  protected virtual void F2() { Console.WriteLine("X.F2"); }
}

class Y : X
{
 sealed protected override void F() { Console.WriteLine("Y.F"); }
 protected override void F2() { Console.WriteLine("X.F3"); }
}

class Z : Y
{
 // Attempting to override F causes compiler error CS0239.
 // protected override void F() { Console.WriteLine("C.F"); }
// Overriding F2 is allowed.
 protected override void F2() { Console.WriteLine("Z.F2"); }
}

Static Class
  1. Static class must have all methods and variables as static.
  2. Even in static class only static constructor can be called and NO instance constructor allowed.
  3. can NOT be instantiated.
  4. static class is Sealed(can not be inherited) by default.
  5. Static class can NOT be abstract class ( as it can not be inherited).
  6. Static class can only inherit system.object class as system.object class is the base class for every class.
  7. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
  8. Use a static class to contain methods that are not associated with a particular object.
Partial Class
a special ability to implement the functionality of a single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword

SOAP and REST

SOAP
REST
Only XML format is allowed for data transfer.
Multiple format like Plain Text, XML, JSON HTML
Stateless by default, but it’s possible to make a SOAP API stateful.
Stateless (no server-side sessions).
While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features.
Less Secure
Requires more bandwidth and computing power
Requires fewer resources.



WCF and ASP.net Services















































Const
Read-only
A constant member is defined at compile time and cannot be changed at runtime.
read-only member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared
They must be initialized as they are declared
Not implicitly static (only single object ) and has to explicitly made static