We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


In C# development when should i choose abstract class over ordinery class.

mu_ravi1 asked
Medium Priority
Last Modified: 2013-12-16

In C# development when should i choose abstract class over ordinery class.
actually i gone through google and iam not able to find the solution.
pls provide me the example when i need to go for abstrat classs.
With Regards
Watch Question

Consultant Software Engineer - .NET Architect
Unlock this solution and get a sample of our free trial.
(No credit card required)
AndyAinscowFreelance programmer / Consultant

Further to the information from IJZ (which is very useful)

An abstract class can NOT have an object of that type.  eg.  If class CAbstract is abstract then the following will not work:
CAbstract obj = new CAbstract();

You can only create objects on classes derived from CAbstract that are themselves not an abstract class.
Navneet.Net Full Stack Developer

Abstract is a basic templete with basic features and basic requirements you would like to have atleast in all your Classes.
In more simple terms it's having a Templete which you can't sell(create object), but can produce objects from it to sell.

Mahmoud_Al_HattabSoftware Architect

well all the above is very useful. Here is an explained example to clarify more:
1- You have the You are making a drawing application. The base interface is IShape:
interface IShape
 void Draw();
 double Area();
The interface defines a contract for all users that this object(that implements IShape) does support the method Draw.
2- Now the rectangle and square have common implementations in the area. Thus lets have the abstract class:
abstract class FourRightSidesShape : Ishape
 public double Length{get;set;}
 public virtual double Width{get;set;}
 public double Area()
  return this.Length * this.Width;

 public abstract void Draw();
//further methods can be added as well even if not from the bas interface.. they can be either abstract or have implementation.

Now notice that you can not create a FourRightSidesShape obbject. You should inherit a Rectangle or Square from FourRightSidesShape:

class Square : FourRightSidesShape
 public override double Width
  get{return this.Length;}
  set{this.Length = value;}

 public void Draw()
 {//drawing code goes here...

Now you can instantiate Square object. No nee to repeat the Area method for the Square and Rectangle. Just the Draw method.

Shortly, the abstract is like the interface except for that:
 1- it can/may contain implementation for methods and properties.
 2- it may/can contain variables.
 3- another third non functional distinction: it is that it can have protected and/or private members(methods, properties, variables... etc). Either abstract methods or with their implementations.

 Well, if you have any further inquiries, please do not hesitate :)

Mahmoud Al-Hattab


not suffcient
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.