Best practice service + model

perk's Avatar


07 Dec, 2010 01:05 PM

I started reading up on RL a week ago, and I really like what i see. I have however a little question on best practice in a certain situation.

When we work on a project at work we always need text to display to the user. This could be small strings of text like "click here to submit", "name", "phone", "email" labels next to the actual input fields, etc. What we have done up until now is store all these bits of texts in an xml file, and load it in the bootstrapping phase of an application. I therefor thought i would make a few classes for RL that can take care of this, and to reuse in each RL application we make from now on. Now on to the question...

I have made a model class that stores a reference to an xml that contains the text. I also need to do the actual loading of the xml, before i can store it in the model. Now, if I follow the best practic (as I understand it) i should make a service that does the loading. Complete the whole process of loading and storing the xml i would need to create two commands, one to start the service loading, and one to feed the xml into the model once the service has completed its task. That is a total of four classes.

Now my question: Would it be a bad practice to integrate a loader into the model, have a command feed a url to the model, let the model take care of the loading by itself and finally dispatch a complete event when it is done? Ergo bypassing the need for the service class.

Alternatively, should I rather create two commands that are also reusable to do the load initiation and model data feed?

  1. 1 Posted by krasimir on 12 Dec, 2010 10:55 AM

    krasimir's Avatar

    Hello perk,

    I think that is a good idea to keep the loading and parsing process out of the model class. It's because now you are loading xml, but let's imagine that you have to load json string, or you have to change the loading from server to the local file system. Then you should change your model class. If you keep these process as a services you will just create another service. Also something else that have to be mention here is that if you combine the loading/parsing and storing of the data in one class you will not be able to use only model's part or only the loading part in another project. You always have to get both of them together and probably you will just write them again.

  2. Stray closed this discussion on 11 Feb, 2011 10:41 PM.

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

Keyboard shortcuts


? 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