I have the issue that I want to be able to capture a set of SNMP messages, and some of them I want to parse to create an instance of a user-defined class. I may for example want to identify whether an SNMP message is a TRAP message, and if it is I want to identify the type of TRAP and create an instance of this type.
Example: SNMP message type: TRAP:ALARM:MINOR_ALARM
In this case I want to instantiate a class of type MinorAlarm, containing the information of the alarm and some well-defined functionality from an interface (like printing the alarm, determining when it happened, ...)
The number of different types will eventually become large and it has to be simple to add new types as well. The current implementation is very limited and messy. It basically consists of a huge if-else statement where only a subset of the types are supported right now.
The name of the specific SNMP type can be obtained from the SNMP message through a string like "22.214.171.124.126.96.36.199" (numbers are completely made up).
I believe that a factory pattern might become too messy here. The guess is that some kind of lookup table would work, but if possible I would like avoid using Reflection (since this will be hard to read and understand).
Some loose thought would be to use some kind of abstract factory with a hierarchical structure. This would resemble the hierarchical structure of the nested structure of the MIB tree. This might be the best idea, but it will still involve digging into some if-else or switch mess. Does anyone have any good ideas how to proceed?