Click here to Skip to main content
15,897,273 members
Articles / Programming Languages / Visual Basic

Abstract Class versus Interface

Rate me:
Please Sign up or sign in to vote.
4.76/5 (382 votes)
7 Jan 2008CPOL4 min read 2.6M   11.1K   559  
Abstract class versus Interface: Usage and Implementation.
This article is meant to be a theoretical and practical overview of Interfaces and Abstract classes. In the article, I have explain the differences between an abstract class and an interface. I have also implemented a demo project which uses both abstract class and interface and show the differences in their implementation with code examples.
using System;

namespace AbstractsANDInterfaces
{
	/// <summary>
	/// Summary description for Employee.
	/// </summary>
	
	public abstract class Employee
	{
		//we can have fields and properties in the Abstract class
		protected String id;
		protected String lname;
		protected String fname;

		//properties
		public abstract String ID
		{
			get;
			set;
		}

		public abstract String FirstName
		{
			get;
			set;
		}
		
		public abstract String LastName
		{
			get;
			set;
		}
		//completed methods
		public String Update()
		{
			return "Employee " + id + " " + lname + " " + fname + " updated";
		}
		//completed methods
		public String Add()
		{
			return "Employee " + id + " " + lname + " " + fname + " added";
		}
		//completed methods
		public String Delete()
		{
			return "Employee " + id + " " + lname + " " + fname + " deleted";
		}
		//completed methods
		public String Search()
		{
			return "Employee " + id + " " + lname + " " + fname + " found";
		}

		//abstract method that is different from Fulltime and Contractor
		//therefore i keep it uncompleted and let each implementation 
		//complete it the way they calculate the wage.
		public abstract String CalculateWage();
		
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Australia Australia
Rahman is a very experienced software developer with 10+ years of experience in different programming languages. Has experience in both Web Application Development and Desktop Line of Business Application development.

At the moment his area of interest are .Net both C# and VB.Net, Client side UI frameworks like AngularJs, Bootstrap, etc. Application Architecture, Dependency Injection, Use case Driven Development, Test Driven Development, MOQ etc.

He has Bachelor of Computing with Distinction Grade from University of Western Sydney.

Comments and Discussions