Question

Suppose I have an Employees data.
Each Employee has its employee type, e.g.: Part-timer, Internee, Manager.
Those types are fixed and used throughout the entire application, and its purpose is read-only.

The question is, should I store those employee types into database, like this :

table employee_type
ID | Name 
--------------------
 1 | Part-timer
 2 | Internee
 3 | Manager

or inside the code, as a static constant variables (or enums), like this in PHP code :

 class Employee
 {
     const EMPLOYEE_TYPE_PARTTIMER = 1;
     const EMPLOYEE_TYPE_INTERNEE = 2;
     const EMPLOYEE_TYPE_MANAGER = 3;
     ...
     ...
 }

The advantage of using the code is, you can use those employee types like this

$employee = new Employee( Employee::EMPLOYEE_TYPE_MANAGER );
...
...
if ( $employee->getType() == Employee::EMPLOYEE_TYPE_PARTTIMER )
{ ... }

So, which one is better ?
Or maybe there is a better solution than both of them ?

Was it helpful?

Solution

If you have (or may have) other tables in your database in which you store the ID, I'd store the definition in a table to enable integrity constraints for the children rows in other tables. If you want to, you could also use the constants, but this redundancy is a possible source of mistakes because you could end with different values in source and in database

OTHER TIPS

I would suggest you make it into the database. and make a panel/form when you want to change the status of an employee. It will make the application robust and more dynamic.

But like you said in here

"Those types are fixed and used throughout the entire application, and its purpose is read-only."

Static data = Constant Value Dynamic data = Database

Still i prefer the database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top