I have a class Transaction that holds a set of requests. Every X seconds the requests in the current transaction are set, and the list of requests is cleared.
Is it ok to design the class Transaction in such way that it will send the requests in the transaction during its destruction, by the destructor?
This means that we allocate a new Transaction, add to it new requests as long as it still alive, and once the destructor is called all the requests will be sent.
This way we can guarantee that:
Is this considered to be a good practice? Or would it be better to use a SendRequests method to send all the requests and clear the list?
A destructor has only one purpose in the C++ language. That is to manage (so it could log, use a helper object or function, etc) the release of resources acquired in the constructor as per RAII. Any other use is going to get you into trouble sooner or later.