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.
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.