I have a project where I transform Messages from one format into another. The messages are identified by an id. I have a MappingTable with the id in the one format and the corresponding id in the other format.
For example: 2000 = 153
The id's are integers
I add all those entrys via:
this.AddMappingEntry(2400, 2005, true, false);
This method adds a mapping entry into a mapping list. I can filter the list via linq, so that I can find the correct mapping if I receive a message with value 2400.
Since the project is launched it is grown quite a bit which lead to many refactorings and to many id's with a special behavior. I have to control if a message is of a special type.
if(message.id == 153)
{
//special behavior
}
How should I handle this most elegant ? Should I use many constants which describe the message type or is there another more elegant way ?
EDIT:
I reword the question. I have Head records and sub records. But the Id's of those records are used throughout the Code. Since there are about 200 different Id's I was wondering what I should do with those magic numbers. The Tool that I am writing is a converter.
The structure is as follows
+------+ +-------------+ +---------+
| DAL +-------> | CONVERTER +----> | WRITER |
+------+ +-------------+ +---------+
The Converter classes look roughly like this
+------------+
|BaseClass |
+-----+------+
^
|
+-----+------+
|BaseRecord +^-------------+----------------------+
+------+-----+ | |
^ | |
| | |
+------+-----+ +-------+--------+ +-------+--------+
| HeadRecord | | RecordType1 | | RecordType2 |
+------------+ +----------------+ +----------------+
The BaseRecord extends the Baseclass and all other classes extend the BaseRecord. In total I have 5 Record types with a recordId 1-5. Inside this record are several subrecordId's (~50) which are only used to identify the Records behind the writer respectively after the writing process.
The problem is that some records read some values from different fields then others which leads to some special cases where I need to identify the record.
This leads to the Problem: I have many magic numbers which nobody knows what they are for, if I use them in my classes and the converter. How do I avoid those magic numbers ? I am afreid that my classes are filled with 50+ const values if I use those. Is there a way to avoid magic numbers and a big bunch of const values ? What is the correct refactoring for this ?