Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for class that interact with database

Is there such thing as standard naming convention for a class that interact with database ( CRUD things or check duplication ). Right now i just named it as Helper, for example a named "Subscriptions" A class that interact with that table will be named "SubscriptionHelper"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LoopinWineBackOffice.Helper
{
    public class SubscriberHelper
    {
        public static bool IsEmailAlreadyInUsed(string email)
        {
            using (var dc = new LoopinWiineContainer())
            {
               return dc.Subscribers.Any(item => item.Email==email.Trim());
            }
        }
    }
}

My sample code is something like this.

like image 387
Sarawut Positwinyu Avatar asked May 17 '12 02:05

Sarawut Positwinyu


People also ask

What are naming conventions in database?

For the traditional naming convention: Database names must only consist of the letters a to z (both lower and upper case allowed), the numbers 0 to 9 , and the underscore ( _ ) or dash ( - ) symbols. This also means that any non-ASCII database names are not allowed. Database names must always start with a letter.

What convention is used in naming classes?

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

What is the naming conventions of a database in SQL?

Though these vary somewhat between SQL “flavors”, SQL columns and table names should begin with a letter, not end in an underscore, and should contain only alphanumeric characters. Column and table names should not contain spaces.

Are naming conventions important in database modeling?

A typical naming convention for constraints mentions the type of constraint, the name of the table, and the names of columns involved. It is important to name constraints so that when the constraint is violated, you know which constraint has been violated and which table is involved.


1 Answers

In my experience [and no offense intended] when classes start getting names like 'Helper' and 'Manager' it's because the purpose of that class hasn't been well defined (and I have been guilty of this in the past myself).

In this case, I would speculate that you haven't really thought about your data access pattern, and you've just got a bunch of ad-hoc SQL in the 'SubscriptionHelper' class.

Now, if you were implementing a standard data access pattern, for example a Repository pattern, your class would be called SubscriptionRepository, and its intent would be alot clearer.

So, in answer to the question - No, I don't think there is a standard 'naming' convention for your scenario. What there are though, are several standard design patterns which you could potentially apply to your system, and through doing so, you would likely end up with a naming convention which is both informative, and meaningful.

Here's a starting point for some well known design patterns for you: http://martinfowler.com/eaaCatalog/, but without knowing more about the project, it would be hard to direct you much further than that.

like image 120
RJ Lohan Avatar answered Oct 31 '22 12:10

RJ Lohan