Models and Commands

Grosmar's Avatar

Grosmar

13 Jun, 2014 10:31 PM

Hello,

As I'm gettng more and more familiar with RL2, I always face the following problem:

I have a model that has a property. If I want to change it, I always have to do some service calls first, so I have a command that do all the service stuff and change the property finally. That's ok.

But how can I prevent that, if some teammate in the future want to change this property directly in my model?
If he changes the porpety directly, and don't use my command, my application become async from the service.
So I should "force" somehow the others to use my command for changing the property, and prevent it changed directly from for example a mediator or another command.

Thanks your advices!

  1. Support Staff 1 Posted by Ondina D.F. on 14 Jun, 2014 10:03 AM

    Ondina D.F.'s Avatar

    Hey,

    So I should "force" somehow the others to use my command for changing the property, and prevent it changed directly from for example a mediator or another command.

    Yeah, put your team mates in chains and punish them in any way you see fit, if they even think of touching the model in a mediator :P

    You could make your model sealable. Look at how Swiftsuspenders seals/unseals a mapping:

    https://github.com/robotlegs/swiftsuspenders/blob/master/src/org/sw...
    https://github.com/robotlegs/swiftsuspenders/blob/master/src/org/sw...

    Use something similar in your model, which should implement an interface. The command could seal the model after setting its property using a sealKey, and unseal it, if/when needed, by using that "top secret" sealKey. Make the model throw an error in the setters of its properties, if a class tries to set its properties while the model is sealed.

    That's just an idea. I hope it helps a little bit. Maybe there are other solutions as well. I'm thinking of guards, but I don' t have enough time right now to think it through.

    Ondina

  2. Ondina D.F. closed this discussion on 11 Jul, 2014 08:09 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac