Skip to main content
fix spelling
Source Link
Kilian Foth
  • 111k
  • 45
  • 302
  • 323

How to handle Factory like-like structures with a huge amount of classes?

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-defined class. I may for example want to identify ifwhether 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 instansiateinstantiate a class of type MinorAlarm, containing the information of the alarm and some well defined-defined functionality from an interface (like printing the alarm, determeningdetermining when it happened, ...)

The number of different types will eventually become large and it havehas 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 "1.1.1.0.2.6.22.33" (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?

How to handle Factory like structures with a huge amount of classes?

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 if 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 instansiate a class of type MinorAlarm, containing the information of the alarm and some well defined functionality from an interface (like printing the alarm, determening when it happened, ...)

The number of different types will eventually become large and it have 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 "1.1.1.0.2.6.22.33" (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?

How to handle Factory-like structures with a huge amount of classes?

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 "1.1.1.0.2.6.22.33" (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?

Source Link
patrik
  • 386
  • 1
  • 3
  • 11

How to handle Factory like structures with a huge amount of classes?

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 if 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 instansiate a class of type MinorAlarm, containing the information of the alarm and some well defined functionality from an interface (like printing the alarm, determening when it happened, ...)

The number of different types will eventually become large and it have 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 "1.1.1.0.2.6.22.33" (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?