Difference between revisions of "Abstract"

From Logic Wiki
Jump to: navigation, search
 
Line 33: Line 33:
  
 
---------------
 
---------------
Related Subjects : [[interface]],  [[Polymorphism]]
+
Related Subjects : [[interface]],  [[Polymorphism]], [[Sealed Modifier]]

Latest revision as of 10:39, 13 June 2017


Once you define the name but not implement the body and all child classes should implement their own bodies under defined name it's called abstract.

if you set a method as abstract in a class, you have to define class itself as abstract

if all the members are abstract class can be defined as interface

public abstract class Shape
{
  public abstract void Draw();
}  

Draw method cannot have a method body,

Derived class must implement all abstract members in the base abstract class

Abstract classes cannot be instantiated

Why to use Abstract ?

When you want to provide some common behaviour, while forcing other developers to follow your design

Virtual vs Abstract

Virtual can be overridden but not a must and it can have a body. Abstract must be overridden in derived classes and cannot have a body.

Interface vs Abstract

in Abstract classes there can be implementations


Related Subjects : interface, Polymorphism, Sealed Modifier