Relationships
When building modules in Yours Protocol, there are different ways to create relationships between them. Let's explore these patterns using a game example where characters can equip items.
Direct Relationships
A direct relationship is when one module directly references another module's entities:
Avoid doing this! While this approach works, it creates tight coupling between modules. The character module cannot exist without the items module, making it less reusable.
Indirect Relationships
A better approach is to have modules reference tokens independently:
Here both modules are loosely coupled through the token. The benefits are:
Loose Coupling: The character module doesn't need to know about equippable entities
Modularity: Each module can be used independently
Reusability: The modules can be shared and used in different contexts
For example, the same item token could be:
Equipped by a character
Displayed in a marketplace
Used in crafting
Stored in a vault
Each of these features can be implemented as separate modules without direct dependencies.
Best Practices
We highly recommend using the Indirect Relationship approach. The key features of Yours Protocol are flexibility, modularity, and reusability. It's important for modules to be shareable, which is much easier if each module is self-contained and doesn't directly depend on other modules.
A Direct Relationship may simplify querying slightly in certain scenarios, but we only recommend using it in modules that are specific to your dApp and ones that you do not intend to share or promote as reusable.
Last updated
Was this helpful?