Implement uniform name using Interface

Sourav.Kayal
Posted by in C# category on for Beginner level | Points: 250 | Views : 3580 red flag

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.

Page copy protected against web site content infringement by Copyscape

About the Author

Sourav.Kayal
Full Name: Sourav Kayal
Member Level: Silver
Member Status: Member,MVP
Member Since: 6/20/2013 2:09:01 AM
Country: India
Read my blog here http://ctrlcvprogrammer.blogspot.in/
http://www.dotnetfunda.com
I am .NET developer working for HelixDNA Technologies,Bangalore in healthcare domain. Like to learn new technology and programming language. Currently working in ASP.NET ,C# and other microsoft technologies.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)