Behaviours: Should I always return a reference to the behaviour on its methods? [closed]

I'm writing a small game to sharpen my programming skills, and I've chosen to use behaviors (that basically is a class that modifies its parent, to do things like movement, damage and stuff) to avoid duplicating code... maybe...

Whenever I need to modify the properties of a behavior, I need to get it from the "Actor", like this:

actor.getBehaviour(BehaviourType).method();


It's OK until I need to modify multiple properties, like following:

actor.getBehaviour(BehaviourType).method();
actor.getBehaviour(BehaviourType).setFoo(10);
actor.getBehaviour(BehaviourType).setBar("privet", "russian_hello");


Wouldn't that be more convenient if I just return a reference to the behavior on every method (every method needed)?:

actor.getBehaviour(BehaviourType).method().setFoo(10).setBar("privet", "russian_hello");


I apologize for any mistakes or broken logic (including broken grammar).

Thank you very much and have a nice day/afternoon/night/pokemongo/vim>sublime but i use sublime anyways!

• TBH, I think you'll get your answer only when you'll be done with your project. – Vaillancourt Jul 19 '16 at 17:16
• I think this is much more a general programming question than anything specific to games. – Sean Middleditch Jul 19 '16 at 17:30
• What exactly are you looking for here? Your only actual question appears to be "would this be more convenient?" which is pretty subjective in nature. Are you asking how you'd make this change, or what the downsides might be? Or are you purely looking for a discussion about the pros and cons of the technique? You might want to ask on GDNet instead. – Josh Jul 22 '16 at 15:33

YourBehaviour behaviour = actor.getBehaviour(BehaviourType);