3

In some projects I see that a dummy record is needed to create in Db in order to keep the business logic go on without breaking the Db constraints.

So far I have seen its usage in 2 ways:

  • By adding a field like IsDummy
  • By adding a field something called ObjectType which points a type: Dummy

Ok, it helps on what needs to be achieved.

But what makes me feel alert on such solutions is sometimes you have to keep in mind that some dummy records exist in the application which needs to be handled in some processes. If not, you face some problems until you realize their existence or until someone in the team tells you "Aha! You have forgotten the dummy records. You should also do..."

So the question is: Is it a good idea to create dummy records to keep business logic as it is without making the Db complain? If yes, what is the best practice to prevent developers from skipping their existence? If not, what do you do to prevent yourself from falling in a situation where you end up with an only option of creating a dummy record?

Thanks!

5
  • Could you expand a little on what the IsDummy and ObjectType are actually used for? Why do you need these for your business constraints? Nov 10, 2010 at 16:56
  • 3
    You should never need to create a dummy record. I fail to see what purpose a dummy record serves? How does the DB complain if you don't use a dummy record? Are you saying that some select statements use this dummy to return a recordset that can be added?
    – Scottie
    Nov 10, 2010 at 16:57
  • 2
    With nearly 15yrs of database development I don't think ive run into this situation once. That's not to say its impossible, just that I think it's an indication of an incorrect design. Can you give a more concrete example of where/why this problem exists.
    – Jamiec
    Nov 10, 2010 at 16:57
  • I understand. Let do my best to explain it with a simple case. Assume that you have a Package object and you have implement a business logic that a Package without any content cannot be created. YOu created some business layer rules and designed your Db with relevant constraints. But after some years a new feature is requested and to accomplish that you have to be able to create a package without a contnent. To overcome this, you decide to create a dummy content which is not visible on UI but lets you to create an empty package. Could I make it a bit more clear?
    – pencilCake
    Nov 10, 2010 at 19:05
  • Haha. I just went through and up-voted every response (including comments) arguing against use of said "dummy objects" -- at the time it was all 10 of them.
    – user166390
    Nov 11, 2010 at 4:33

8 Answers 8

6

Using dummy records is inferior to getting the constraints right.

There's often a temptation to use them because using dummy records can seem like the fastest way to deliver a new feature (and maybe sometimes it is), but they are never part of a good design, because they hide differences between your domain logic and data model.

5

Dummy records are only required when the modeller cannot easily change the Database Definition, which means the definition and/or the data model is pretty bad. One should never end up in a situation where there has to be special code in the app layer to handle special cases in the database. That is a guaranteed maintenance nightmare.

Any good definition or model will allow changes easily, without "affecting existing code".

All business logic [that is defined in the Database] should be implemented using ANSI SQL Constraints, Checks, and Rules. (Of course Lower level structures are already constrained via Domains/Datatypes, etc., but I would not classify them as "business rules".) I ensure that I don't end up having to implement dummies, simply by doing that.

If that cannot be done, then the modeller lacks knowledge and experience. Or higher level requirements such as Normalisation, have been broken, and that presents obstacles to implementing Constraints which are dependent on them; also meaning the modeller failed.

I have never needed to break such Constraints, or add dummy records (and I have worked on an awful lot of databases). I have removed dummy records (and duplicates) when I have reworked databases created by others.

4

I've never run across having to do this. If you need to do this, there's something wrong with your data structure, and it's going to cause problems further down the line for reporting...

4

Using Dummies is dumb.

In general you should aim to get your logic right without them. I have seen them used too, but only as an emergency solution. Your description sounds way too much like making it a standard practice. That would cause more problems than it solves.

3

The only reason I can see for adding "dummy" records is when you have a seriously bad app and database design.

It is most definitely not common practice.

If your business logic depends on a record existing then you need to do one of two things: Either make sure that a CORRECT record is created prior to executing that logic; or, change the logic to take missing information into account.

2

I think any situation where something isn't very easily distinguishable as "business-logic" is a cause for trying to think of a better way.

The fact that you mention "which points a type: Dummy" leads me to believe you are using some kind of ORM for handling your data access. A very good checkpoint (though not the only) for ORM solutions like NHibernate is that your source code VERY EXPLICITLY describes your data structures driving your application. This not only allows your data access to easily be managed under source control, but it also allows for easier debugging down the line should a problem occur (and let's face it, it's not a matter of IF a problem will occur, but WHEN).

When you introduce some kind of "crutch" like a dummy record, you are ignoring the point of a database. A database is there to enforce rules against your data, in an effort to ELIMINATE the need for this kind of thing. I recommend you take a look at your application logic FIRST, before resorting to this kind of technique. Think about your fellow dev's, or a new hire. What if they need to add a feature and forget your little "dummy record" logic?

You mention yourself in your question feeling apprehension. Go with your gut. Get rid of the dummy records.

2

I have to go with the common feeling here and argue against dummy records.

What will happen is that a new developer will not know about them and not code to handle them, or delete a table and forget to add in a new dummy record.

I have experienced them in legacy databases and have seen both of the above mentioned happen.

Also the longer they exist the harder it is to take them out and the more code you have to write to take into account these dummy records which could probably have been removed if you just did the original design without them.

2

The correct solution would be to update your business logic.

To quote your expanded explanation:

Assume that you have a Package object and you have implement a business logic that a Package without any content cannot be created. YOu created some business layer rules and designed your Db with relevant constraints. But after some years a new feature is requested and to accomplish that you have to be able to create a package without a contnent. To overcome this, you decide to create a dummy content which is not visible on UI but lets you to create an empty package.

So the at one time to a package w/o content was invalid thus business layer enforced existence of content in a package object. That makes sense. Now if the real world scenario has changed such there is now a need VALID reason to create Package objects without content it is the business logic layer which needs to be changed.

Almost universally using "dummy" anything anywhere is a bad idea and usually indicates an issue in implementation. In this instance you are using dummy data to allow "compliance" with a business layer which is no longer accurately representing the real world constraints of the business.

If package without content is not valid then dummy data to allow "compliance" with business layer is a foolish hack. In essence you wrote rules to protect your own system and then how are attempting to circumvent your own protection. On the other hand if package without content is valid then business layer shouldn't be enforcing bogus constraints. In neither instance is dummy data valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.