I have a class representing a data stream that basically reads or writes to a file, but first the data is encrypted / decrypted, and there is also a main codec object that handles media access.
I'm trying to write this class in a RAII way, and I need a clean, nice, comfortable design.
My concern is that a lot of work is being done in the designer now. Before the object I / O procedures can be safely used, first of all, it is necessary to initialize the codec (this is not very demanding), but then the key is taken into account, and crypto and other things are initialized - this requires some analysis of the media, which take up quite a bit of computation.
Now I do all this in the constructor, which makes it take a lot of time. I am considering moving the crypto init material (most of the work) from ctor to a separate method (for example Stream::auth(key)), but again this will lead to some responsibility for the class user, since they need to be run auth()before they invoke any I / O operations. It also means that I will need to put a check in I / O calls to make sure it has been called auth().
Do you think a good design?
PS I read a similar question, but I really could not apply the answers to this case. They mostly look like "It depens" ...: - /
thank
source
share