I am right now facing issue with my design. I am handling situation of master-server and semi-slave-client. I have server which practically speaking – can do whatever it desires. (Lets don't deconstruct network layer, as it is already working decently enough for my own needs.)
I attempt to use Object Pool design pattern, and I have base object – lets call it ManagedObject, as it is base type of object. The ManagedObject stores all necessary data/information which are necessary for application to run. I have my own system which synchronise state of storage inside of client and server, so it is as well working properly.
Okay after really long intro to my issue:
Issue is that my Server can see AND can edit data which it is owner of (same for client). I would love to have one type saved and used exactly in the same way, lets assume this code:
class ManagedObject
{
private:
some::other::ManagedObject managedObject;
public:
explicit ManagedObject(char* buffer);
};
Which in this case we have base layout class which contains some::other::ManagedObject. I personally would love to dynamically in run-time make this variable const or not, but I just know it does not work like that (and shouldn't).
I have thought about creating unified interface for access to it, but it would as-well not be possible, as interface have to declare it's type, so best I could get was that:
some::other::ManagedObject getMut(); // Yes copy
const some::other::ManagedObject& get();
which is not really that helpful for my case, as it's two methods which user have to know what to do and when to not just straight make tons of copies of same object. Moreover, I have to observe if object has changed, and send updates to other instances.
My last and current attempt was to make everything copy by default, and create "transaction" mechanism, which in case of commit() method would just verify if it is possible (allowed).
Here is a question:
How can I design my code to avoid copy by default approach, and make it better/more efficient as whole system.
Annotations:
I know it is premature optimisation, but I want this part of the system, to run smoothly, as It will be the aorta of my game-like project.