How classes and objects work

This page describes the relationship between classes and objects, which is fundamental to how the Google Wallet API works. This page also covers how objects link to users.

Classes and objects

The Google Wallet API uses the concept of an object to digitally represent a single user's physical transit passes. The API uses the concept of a class to allow management of data common across all users. To cover specific use cases, each vertical has its own respective object and class.

For example, each Google Wallet a user has in their Google Wallet app is represented by one TransitObject, which references a TransitClass.

To make it easier to implement changes that need to apply to all transit passes, every object references a class.

A class contains common data across objects. For example, TransitClass stores the transitType, while TransitObject stores an individual's ticketNumber. The class and object relationship might be one-to-one, but a class can be referenced by many objects.

Changes made to the class or object propagate immediately. Users can see these changes on the Google Wallet app when they sync.

Objects and linking

The Google Wallet API uses the concept of an Object to represent transit pass. For example, an TransitObject represents each transit pass a user has in their Google Wallet app.

After a user clicks the Add to Google Wallet button to add transit pass, the API inserts an Object that establishes a link between the object and the user. This means that when the user clicks the button again, a link already exists to Object.

If a user removes their Pass from the Google Wallet app, the link to the corresponding Object is de-linked. This means that a user can click the Add to Google Wallet button again, to re-establish that link without a new Object.

When you develop your Pass, we recommend that you use a new Object id between adds because the API doesn't re-insert an Object that matches an id.

Remember, when you remove a Pass from your account, you don't lose your Object. The Object is only de-linked from your account, and you can link to it again.