Is there a MQTT variable object?


I have been building IoT and using MQTT to send messages between them. I have been using PlatformIO Adruino coding. Then coding all the publish and messages for MQTT updates using PubsubClient library. Is there a better way? Is there a library that has a MQTT variable object that automatically handle the publishing when a variable changes?

Thanks for the help.