R
Richard Pope
I have some existing code that I am trying to upgrade to c++. The data in
question is two bytes, which are used to identify what information is
requested from an industrial computer (a PLC). The first few bits represent
the "category" of the data, and determine how the rest of the two bytes are
interpreted.
The existing code extracts various details from the data, but always uses a
switch statement on the category.
I could write a single class in c++, but I would have a switch statement in
every member function. This doesn't feel right somehow.
I could have a class for each category (inheriting from an ABC) but how do I
use them in practise? Do I need some kind of factory class that creates the
correct class, based on the category it extracts from the data?
question is two bytes, which are used to identify what information is
requested from an industrial computer (a PLC). The first few bits represent
the "category" of the data, and determine how the rest of the two bytes are
interpreted.
The existing code extracts various details from the data, but always uses a
switch statement on the category.
I could write a single class in c++, but I would have a switch statement in
every member function. This doesn't feel right somehow.
I could have a class for each category (inheriting from an ABC) but how do I
use them in practise? Do I need some kind of factory class that creates the
correct class, based on the category it extracts from the data?