How to implement uniform naming using interface.
Implement uniform naming convention using Interface
In this tutorial we will learn how to maintain uniform
naming convention throughout application. In application development we implement
various classes according to need. Now, the CRUD (Create, Read, Update,Delete)
operation is almost common in each and every class.
The great problem of class implementation is naming
convention. For example, lets thing that we want to perform CRUD operation on
Employee and customer class. To perform Inset operation one may use
InsertEmployee() function where another may use EmployeeInsert() function. It
makes problem in software development.
To solve this naming problem we can use Interface and if we
implement each class from interface, then it will get solve.
Let’s create simple ICRUD interface.
interface ICRUD
{
void Insert();
void Update();
void Delete();
}
Now we will implement both Employee and Customer class from
ICRUD. Have a look on below code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DesignPattern
{
interface ICRUD
{
void Insert();
void Update();
void Delete();
}
public class Employee :ICRUD
{
public String EmpName { get; set; }
public String SurName { get; set; }
public void Insert()
{
Console.WriteLine("Name:- " + this.EmpName);
Console.WriteLine("Surname:- " + this.SurName);
}
public void Update()
{
Console.WriteLine("Name:- " + this.EmpName);
Console.WriteLine("Surname:- " + this.SurName);
}
public void Delete()
{
Console.WriteLine("Name:- " + this.EmpName);
Console.WriteLine("Surname:- " + this.SurName);
}
}
public class Customer : ICRUD
{
public String CusName { get; set; }
public String CusSurname { get; set; }
public void Insert()
{
Console.WriteLine("Name:- " + this.CusName);
Console.WriteLine("Surname:- " + this.CusSurname);
}
public void Update()
{
Console.WriteLine("Name:- " + this.CusName);
Console.WriteLine("Surname:- " + this.CusSurname);
}
public void Delete()
{
Console.WriteLine("Name:- " + this.CusName);
Console.WriteLine("Surname:- " + this.CusSurname);
}
}
}
Here we
have implemented Insert(), Update() and Delete() function in each class.
Let’s implement client code
Now we will create client code to call Insert() and Update()
method. Have a look on below code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DesignPattern
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Employee Information");
Employee e = new Employee();
e.EmpName = "Sourav";
e.SurName = "Kayal";
e.Insert();
Console.WriteLine("\n Customer Information");
Customer C = new Customer();
C.CusName = "Ram";
C.CusSurname = "Kumar";
C.Update();
Console.ReadLine();
}
}
}
Output:-
Conclusion
Here we have learned how to implement uniform naming convention in our application. Hope you have enjoyed it.