Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


What's the proper name for this class?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 alnite   Crossbones+   -  Reputation: 2132

Like
0Likes
Like

Posted 09 February 2013 - 05:11 PM

I'm writing a class that inserts/updates or deletes records to a database table.  I can't come up with the proper name for this class.

 

DBInsertor? Sounds pretty stupid.

 

DBRecord?  It's ambigous as it doesn't represent any DB record or model.

 

DBRecordKeeper?  It doesn't keep or store records.

 

Any ideas?



Sponsor:

#2 Madhed   Crossbones+   -  Reputation: 3129

Like
0Likes
Like

Posted 09 February 2013 - 05:15 PM

DBMutator?

 

Can you post an example of how you would use that class?



#3 Waterlimon   Crossbones+   -  Reputation: 2634

Like
0Likes
Like

Posted 09 February 2013 - 05:22 PM

RecordDBProxy? :P

o3o


#4 alnite   Crossbones+   -  Reputation: 2132

Like
0Likes
Like

Posted 09 February 2013 - 05:32 PM

I would have a text file with the values to be stored to the database.  For example:

 

first_name: "John"

last_name: "Smith"

 

Then it reads this text file, parses the column names, checks if the column names actually exists in the database, then stores them.  It creates a new entry if the values do not exist.  It updates the entry if it already existed.  It can also delete an entry based on a certain criteria, for example, by first_name.

 

So I would use it like this:

 

// Initialize db bla, bla bla

db_whatever.insert("datafile");

db_whatever.update("datafile");

db_whatever.delete("first_name", "John");

 

I was thinking DBRecord sounds the closest, but it doesn't represent the data.  It inserts data into database.

 

edit: It may also extract data from database.


Edited by alnite, 09 February 2013 - 05:35 PM.


#5 Madhed   Crossbones+   -  Reputation: 3129

Like
1Likes
Like

Posted 09 February 2013 - 05:41 PM

Smells pretty anti SRP to me...

 

anyway, from the methods shown, DBContext, DBConnection, or just Database?



#6 alnite   Crossbones+   -  Reputation: 2132

Like
0Likes
Like

Posted 09 February 2013 - 07:58 PM

Smells pretty anti SRP to me...

 

Single responsibility principle?  I would say it is, at method-level, rather than class-level :D

 

 

anyway, from the methods shown, DBContext, DBConnection, or just Database?

 

DBContext and DBConnection doesn't sound bad.  I was looking at C# documentation, and came across: TableAdapter or DataAdapter, which might be a good candidate too.



#7 Khatharr   Crossbones+   -  Reputation: 3036

Like
1Likes
Like

Posted 09 February 2013 - 09:17 PM

DBRecordInserterUpdaterAndOrDeleter

or possibly

DBRecordThingDoer

or just

DBSecretary

Edited by Khatharr, 09 February 2013 - 09:18 PM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#8 Polarist   Members   -  Reputation: 160

Like
0Likes
Like

Posted 09 February 2013 - 09:53 PM

DBRecordInserterUpdaterAndOrDeleter

 

I vote for this.  Clear and to-the-point.

 

But honestly, if you're set on that set of functionality (file i/o AND database query), then you'll want a fairly non-standard name to denote that it carries a non-standard role.

 

I would have suggested something like DBBasicConnection because of it's similarity with a standard idea of a Connection UNTIL you mentioned that insert() and update() functions take filenames, that kind of throws standard out the window.



#9 AllEightUp   Moderators   -  Reputation: 4267

Like
0Likes
Like

Posted 10 February 2013 - 01:10 AM

If you take this from a top down manner:

 

It relates to databases which suggests to me a "database" or "db" namespace instead of trying to work that descriptive bit into the name directly.

 

It does three things which suggests this is a management class or a supervisor or some controller type class which is top level to decide what functionality to perform.

 

I tend to use 4 variations of description based on ownership level:

1)  The "manager", owns the item in question and can perform the suggested operations directly.

2)  The "controller", doesn't own the item but tells other systems what is to be done.

3)  The "supervisor", which is simply a decision engine around the item in question.  (This is a subtle difference from controller.)

4)  The "processor", which is used to run through many items and add tags, make lists, whatever for other things to deal with.

 

So, given the original question, I would start by using a namespace to wrap the concept instead of trying to put it in the class name.  The language was not specified but the names suggest a C/C++ background so that's what I'll assume.

 

namespace db/database { class Record[xxx] }

 

Insert proper descriptive item into "xxx".  I'm not much of a person for coding standards but I do like logically organized naming conventions.  Hopefully my description of the way I name things might help.



#10 Mussi   Crossbones+   -  Reputation: 2093

Like
0Likes
Like

Posted 10 February 2013 - 05:20 AM

Why not break it up a little? Have a DBParser, DBEntry and a DBController(or something similar).

#11 dmatter   Crossbones+   -  Reputation: 3293

Like
3Likes
Like

Posted 10 February 2013 - 07:48 AM

These kinds of classes are common in enterprise applications and web development.

If, as you say, this class is providing Create, Read, Update & Destroy (CRUD) operations on a table then you have implemented the Data Access Object (DAO) pattern and I would stick those 3 letters on the end of the class e.g. "HighscoreDao".

There is another, related pattern that operates at a slightly higher level of abstraction from a DAO, it called the Repository pattern. A repository maps between some kind of persistent storage and collections of domain objects, for example a "MonsterRepository" might have to collaborate between multiple database operations in order to provide calls such as getMonstersForLevel.

#12 Bregma   Crossbones+   -  Reputation: 5369

Like
0Likes
Like

Posted 10 February 2013 - 08:12 AM

Finding the verbs in your system and creating classes for them is the classic procedure-oriented antipattern.  Not that there's a lot wrong with procedure-oriented design, unless what you're trying for is object-oriented design so you can take advantage of many of its long-term benefits.  Using classes and object for procedure-oriented design will bring you and the people who have to maintain your code grief.

 

In good OO design, you look for the nouns (object) in your system and create classes for them, then look for the verbs that act on the nouns and create functions for them.  If you're using your noun in the subjective case, you probably have a member function, and if it's in the objective case, you probably pass it as a function argument.  Not a hard-and-fast rule.

 

Using an agent noun ("eg. a 'manager' is something that performs the action denoted by the verb 'to manage') in place of the verb itself for a class name is still procedure-oriented programming.  Classes are nouns, functions are verbs.

 

My guess is that the original requirement was to be able to insert, remove, or update rows in a table in a relational database, or maybe (key, value) pairs in a persistent lookup table (what the folk who learned all their computer science off marketing whitepapers call a nosql database).  I image there are various additional verbs for those nouns for performing metaoperations (like connecting to the RDBMS, fetching a row, committing a transaction).

 

Just remember: nouns are classes, verbs are functions.


Stephen M. Webb
Professional Free Software Developer

#13 cozzie   Members   -  Reputation: 1757

Like
0Likes
Like

Posted 10 February 2013 - 08:45 AM

DBManager, with specific functions for deleting, updating, creating etc.



#14 Flimflam   Members   -  Reputation: 657

Like
0Likes
Like

Posted 13 February 2013 - 02:35 AM

I'd personally go with something like DBModifier or maybe even DBController if it was my project. 



#15 Ravnock   Members   -  Reputation: 293

Like
0Likes
Like

Posted 13 February 2013 - 08:11 AM

what about DataAccessObject (DAO)?

 

http://en.wikipedia.org/wiki/Data_access_object



#16 LorenzoGatti   Crossbones+   -  Reputation: 2761

Like
0Likes
Like

Posted 15 February 2013 - 02:55 AM

I usually find this sort of class that encapsulates all SQL operations called a DAO; they cover the whole spectrum from dumb and generic (often simple CRUD operations, with the extreme of supporting query builders that write WHERE clauses on the fly) to complex and specialized (e.g. methods executing multiple or different SQL statements depending on data). The common trait is avoiding, or at least abstracting and minimizing, "business" logic that goes beyond accessing data and treating SQL errors.

 

Typical naming patterns refer to the database tables, under the assumption that different tables have different purposes and DAO changes follow table chages.  For example a DAO that operates on the Widget table only can be called "WidgetDAO", while one that combines access to the Widget, Gadget and Screw tables (either because they are considered a logical grouping or because they are actually used together) could be called "MechanicalWorkshopDAO".


Produci, consuma, crepa




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS