Design/Architecture Advice

Hello – I’ve been working with Defold now in my spare time on a project for a while and I am about to go in and overhaul some of the subsystems that I think I may have built incorrectly the first time. Apologies if this general a question isn’t a good fit for the forum.

The domain model I have come up with is below. The main idea it is trying to capture is that people, buildings and vehicles in a town may or may not have Insurance Policies.

The question I have is - what is the best way to implement the relationship between Policy Instance and instances of Insureble in Defold?

I was thinking to give each Policy Instance a url attribute that would allow it to message the Insurable item it references – and to also have a url on the Insurable item referencing the policy.

The use case I am a little concerned about is when there is an accident I need to determine from the list of Insurable instances which insurance policies they have so I can determine how much money the player can collect.

The way I can do this efficiently is to have a “Global” table which links Insurable instances to policies and policies to products so that I can iterate through and calculate this whenever needed.

However this approach doesn’t “feel” right – it feels like there is a more natural message-passing style way to accomplish this.

What I’ve tried to do before is to iterate over the Insurable items and send a message to each Policy to return its details and then aggregate in some way, but it ends up having to pause and wait a cycle before the information is ready and I have to thread the info up to the GUI in a kind of strange way.

I guess I am still kind of stuck in “Object Oriented” thinking where I want to rely on an object graph and behaviors to implement this system.

Hopefully this question makes sense – please let me know if there is anything I can clarify.

Thanks!
Alex

2 Likes

Are all of the boxes in the picture their own scripts or Lua modules? Why not collect all of the data in a single structure instead of spreading it over multiple scripts? If there’s a clear connection between Insurable and Policy it makes sense to gather the data in a single place instead of spreading it out.

2 Likes

Don’t use Defold’s script instances for that. Simple Lua modules would do the trick.

2 Likes

Hi - each insurance policy is an instance of an issued policy – something that is associated to an Insurable Item like a building or person or vehicle - but no the policies themselves do not need to be script items in the game .

The insurable elements are active in the game – so each person and building and vehicle are actually items that can have accidents - and these are already script elements.

It sounds like the advice you are giving is to store the instances of the insurance policies in a single module which can be referenced easily, and even this module could hold a reference to the Insurable items in a lookup table.

Then when an accident occurs I can consult the Insurance Module with a list of Insurable items and determine which ones had coverage, etc.

Does this match what you guys were thinking?

Thanks for answering!
Alex