Needing a Recap : Model and/or Proxy

thomas.thorstensson's Avatar

thomas.thorstensson

18 Feb, 2014 12:29 PM

Having worked with Robotlegs and Pure MVC I Sometimes still ponder the question what the best use of Proxies is in Robotlegs.

I understand Proxies to be classes that allow you to set values of value objects or more often retrieve them. They are the 'mediators' of value objects.

In my practice I often however let classes that begin with the name Service, set the values of any Value Object, and I use a Model class (actor) to notify the framework of such Value Objects. My flow can be

Command --> Calls Service, service loads data and populates VO --> Command catches service updated VO and calls Model to notify framework of updated VO and do any logistics.

So my Model acts like a Proxy? If using a Proxy class where in the above flow would it come in. I guess the deeper question is what is the difference between a Model and a Proxy. And Should the model reference a Proxy?

Many thanks for any clarity or recommended best practice or "day in the office and I Am having coffe and this is what I do!" feedback.

Thanks in advance
Thomas

  1. Support Staff 1 Posted by Ondina D.F. on 18 Feb, 2014 02:16 PM

    Ondina D.F.'s Avatar

    Hi Thomas!

    I'm drinking coffee while answering your questions;)

    I guess the deeper question is what is the difference between a Model and a Proxy.

    PureMVC:
    Proxy code manipulates the data model, communicating with remote services if need be to persist or retrieve it. The Proxy may be used not only to control access to data but also to perform operations on the data as may be required to keep that data in a valid state.

    Robotlegs MVCS has split the responsibilities of a pmvc Proxy into 2 classes, Model and Services :

    Model: manipulates the data and holds the state of the application

    [https://github.com/robotlegs/robotlegs-framework/wiki/Best-Practice...] [https://github.com/robotlegs/robotlegs-framework/wiki/Best-Practice...]

    Service: accesses external resources (remote servers, file system..)

    https://github.com/robotlegs/robotlegs-framework/wiki/Best-Practice...

    In PureMVC, there is something called a SmartVO, which is kind of similar to a robotlegs' Model, but not the same.
    http://forums.puremvc.org/index.php?topic=1293.msg5973#msg5973
    http://forums.puremvc.org/index.php?topic=1729.0

    In PureMVC, there are variations on the Proxy pattern:

    • Remote Proxy, where the data managed by the concrete Proxy is in a remote location and will be accessed via a service of some sort.

    • Proxy and Delegate, where access to a service object needs to be shared between multiple Proxies. The Delegate class maintains the service object and controls access to it, ensuring that responses are properly routed to their requestors.

    • Protection Proxy, used when objects need to have different access rights.

    • Virtual Proxy, which creates expensive objects on demand.

    • Smart Proxy, loads data object into memory on first access, performs reference counting, allows locking of object to ensure no other object can change it.

    And Should the model reference a Proxy?

    Not if you use robotlegs MVCS, where a Proxy would be a Service class. You can, however, inject Models (better as an interface) into Services, if you need /want to.

    But, Robotlegs MVCS != Ten Commandments.
    So, you're free to design your classes as you wish, like in using a Proxy (Model+Service) à la PureMVC.
    Personally, I like having separate Models and Services, each with its own distinct role/repsonsabilities/concerns.

    Ondina

  2. 2 Posted by thomas.thorsten... on 18 Feb, 2014 02:27 PM

    thomas.thorstensson's Avatar

    Ondina

    Glad to hear that you had some coffe. Always good with a cup of Java as we say.

    This response is very clear and I now much better understand what is the specifics of the MVCS idea in relation to Proxy and the comparison to MVC was great. I Shall stick to my Model Services approach in RL. But might further inspect the Proxy approach in PureMVC.

    Many Thanks

    Thomas

  3. Support Staff 3 Posted by Ondina D.F. on 19 Feb, 2014 09:15 AM

    Ondina D.F.'s Avatar

    You're welcome, as always!

  4. Ondina D.F. closed this discussion on 19 Feb, 2014 09:15 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