0

I have an object that acts as a "bridge" between objects and I'm not really sure if it has a name.

Unity (the game engine) lets me build a concrete object and then link those objects in the inspector at design time. For obvious reasons, I can't link objects that are created at runtime.

I've overcome that by creating this class:

class ManagerBridge : ScriptableObject
{
    public Manager instance { get; set }
}

I can then create an instance of this object at design time, in the Unity editor, and link it to any object that needs to use the manager:

class ManagerUser : MonoBehaviour
{
   public ManagerBridge manager; // filled in automatically in Unity

   public void Update()
   {
        if(manager.instance != null)
            manager.DoSomething();
   }
}

And the manager sets itself on startup:

public class Manager : MonoBehaviour
{
    public ManagerBridge bridge;

    public void Awake() // called when the manager is created by Unity
    {
          bridge.instance = this;
    }

    public void DoSomething() { }
}

So anyways, the "bridge" object does nothing but store a reference to and allow access to the real Manager object. I'm pretty sure it has to duplicate the Manager's interface to qualify as a proxy, so what the heck should I call this thing?

Thanks.

0

Your ManagerBridge is just a data structure with one field, so it doesn't really follow any pattern or have a special name. Design patterns generally describe the behavior of objects, not their internal representation.

However, as you mentioned, you could turn it into a proxy by having Manager and ManagerBridge implement a common interface and ManagerBridge delegating calls to the internal instance.

0

This seems to be similar to the use of StringHolder and the like for CORBA integration in Java, so would be 'holder' idiom, though that's more often used to implement 'out' parameters in pass-by-value languages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.