tags:

views:

53

answers:

2

Consider the case of a simple news article web application that has a DB table column of "Status" that is accessible by a radio button set of:

Status - [x] Publish [ ] Draft [ ] Archive

...where "Publish" shows an article publicly and "Draft" and "Archive" do not. Functionally "Draft" and "Archive" do the same thing but carry additional meta data meanings. The two functional states of "show" and "hide" along with the meta data of "publish", "draft" and "archive" are intermixed in the same column of "status".

Is this a good practice? While this is a very simple case, larger cases might reveal flaws with such a practice (or not...).

A: 

In this instance, I would say that this is the appropriate functionality.

We've all seen WTF's in the media where someone accidentally hit show[x] and draft[x] at the same time.

The way it is now, it is impossible to accidentally show a draft. This is important in newspapers as reporters are notorious for stuff like:

John Doe, of StackOverflow said, "---I can't remember what that ugly f*cker said - Check the tape and fill in later"

Which probably shouldn't be printed.

chris
+2  A: 

Functional states are about behavior - they do not need to be modeled in your database. If your business logic only cares about "showing" articles with a status of "Published" - there's no reason to double the complexity of your data with a Show column.

At the point that you decide your business logic needs additional data to make the decision whether to show or hide an article (perhaps an IsApproved flag), then you can store that data.

Looking at it from a different angle - if you were to add another column of "Show", then what would an article with a status of "Draft" and "Show" = 1 do? According to your business rules, that is an invalid state.

Mark Brackett