Search Unity

Fixing Unity’s tendency to object coupling: The MessageBus

Discussion in 'Scripting' started by franciscotufro, Apr 18, 2015.

  1. franciscotufro

    franciscotufro

    Joined:
    Nov 5, 2012
    Posts:
    2
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Good message. But hardly worth tackling in roll a ball. :)

    While you are picking at the tutorials and coding practice you should also look at Unity's encouragement to break encapsulation by making everything public.
     
  3. Fajlworks

    Fajlworks

    Joined:
    Sep 8, 2014
    Posts:
    344
    Interesting read. However, I don't understand why you would need to necessarily make all of your scripts inherit from MessageHandler, wouldn't an simple IMessageHandler interface be enough? That way I could give some random objects that do not inherit from MonoBehaviour also the ability to subscribe and handle messages. Otherwise, good work!
     
  4. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    The pattern is similar, but I found that adhering to the Observer Design Pattern has worked very well... and I don't have to be concerned with extension limits nor be concerned with a singleton.

    it's a fire and forget for the Provider, scalable, very little that requires cleanup... allows multiple providers with one-to-many, many-to-one, or many-to-many relationships.

    observers can parse provider messages and choose to ignore or handle message in a custom manner...