Fremus.co.za

Demistifying Life and Web Development

Abstract classes vs Interfaces

What is an abstract class and how is it different from a regular class? An abstract class is an incomplete class that acts as a base class for other other classes to inherit from. An abstract class could be written this way:

    public abstract class MyAbstractClass
    {
        public abstract void GetTotal();
    }

And then a class that inherits from it could look like this:

    public class Tester : MyAbstractClass
    {
        public override void GetTotal()
        {

        }
    }

The Tester class is required to implement the GetTotal method otherwise an error will occur.

Abstract classes can contain methods, properties and events whereas interfaces only contain methods. Interfaces are useful because you can use them across multiple projects, in other words if you need to implement some functionality in your code from an outside source then you could use an interface to expose its methods.

  • Share/Bookmark
posted by fr3dr1k in C# and have No Comments
Tags:

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment
Get Adobe Flash playerPlugin by wpburn.com wordpress themes