Skip to content
Advertisement

Avoiding circular depenency between Arena and Portal

I’m trying to resolve this ciruclar dependency while preferebly keeping both objects immutable.

JavaScript

Basically, I need portal to be able to activate itself, and start the arena. Opposite, I need Arena to reset & close itself, and the portal. I found a solution by having two HashMap’s <Arena, Portal> and <Portal, Arena>, however I want to figure out if it’s a better way to solve this for learning and progression.

The classes are made more simple in here, as in reality they have more variables and identifiers.

Advertisement

Answer

Why not a wrapper class for both Arena and Portal:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement