Robotlegs + ActiveRecord Pattern

paulo.campos's Avatar

paulo.campos

14 Oct, 2013 04:55 PM

Hi. I am currently working on a project where we use Weborb WDMF. We use [Bindable] a lot. Since we are moving our focus also for mobile development, It ´s a good time to turn the views loselly coupled from our models, Are there any CONS using this two patterns in conjunction since we have mechanisms to process requests in transactions, handle paging, sorting and many other data management operations?

  1. Support Staff 1 Posted by Ondina D.F. on 15 Oct, 2013 09:31 AM

    Ondina D.F.'s Avatar

    Hi Paulo,

    I have only a theoretical knowledge of the ActiveRecord Pattern. I agree with the author of these articles: http://www.mehdi-khalili.com/orm-anti-patterns-series, especially regarding the violation of the SRP.
    I've seen examples where the Views hold all the logic for accessing a server and binding the results to models, that were also part of the View...From an MVCS point of view, that's not a good practice:)
    On the other side, Robotlegs, as a framework, doesn't care about how you use it, i.e. whether you follow an MVCS or an MVP pattern, or none at all. With Robotlegs 2 you could even inject anything you want into your views.

    Due to my lack of practical experience with ActiveRecord and to your rather broad question, I can't really tell you how to organize your classes. I also don't know how much you already know about MVCS, but if you already understand the roles of each layer, you can easily detect the parts in your code that need to be extracted into separate classes.
    Just in case you're not familiar with the MVCS roles:

    • Services+Models+VOs =responsible for retrieving data, manipulating data, persisting data structures
    • Service = gatekeeper to the outside world, data supplier, data source. Services should encapsulate logic for storing data to external data storage and/or retrieving data from external data sources (persistent data storage: Server, File system…), and informing other actors about the results.
    • Model = deals with data, data modeler, responsible for manipulating the application’s states. A Model should encapsulate all the logic responsible for maintaining the integrity of the data, for manipulating the data, and for informing other actors of changes to the data (through events or signals).
    • VO = data carrier class to shuttle typed data across tiers
    • Controller = Events+Commands = application logic = application’s behavior= use cases
    • Commands act upon Models and Services, usually in response to user interactions with the application
    • View = user interface
    • Mediator = intermediate, intermediary between application and View, wiring the Views to the shared event dispatcher.

    => Services are the intermediaries between an application and the outside world; Mediators are intermediaries between the application and the user interface.

    It ´s a good time to turn the views loselly coupled from our models,

    I fully agree with that:)

    Now, if you need more help with this, just provide more info, and we might find an appropriate solution.

    In the mean time I'll move the discussion from Suggestions to Robotlegs 2.

    Cheers,
    Ondina

  2. 2 Posted by paulo.campos on 15 Oct, 2013 11:45 AM

    paulo.campos's Avatar

    Hi Ondina,

    Thanks for your reply.
    That link was actually very useful. Actually made ​​me understand better why I ended up with spaghetti code :)
    But I get the idea that the productivity achieved with ActiveRecord Pattern is too obvious to ignore, even violating some principles of OO design as SRP. If I can wrap this functionality in Service Layer through an interface, I can get the best of both worlds, abstracting the application of using ActiveRecord .. i think.
    I'm still at the stage of learning RobotLegs framework, and trying to figure out how to glue all these parts. When I actually start writing some code, I'll post my experience with it.
    Best regards.

  3. Support Staff 3 Posted by Ondina D.F. on 15 Oct, 2013 12:28 PM

    Ondina D.F.'s Avatar

    But I get the idea that the productivity achieved with ActiveRecord Pattern is too obvious to ignore, even violating some principles of OO design as SRP.

    Yes, theory is one thing; putting it into practice is another. I think, what really matters, is finding the best compromise between the "best practices" and the requirements of a specific project. Design patterns are there to support a project, not vice versa ;)

    If I can wrap this functionality in Service Layer through an interface, I can get the best of both worlds, abstracting the application of using ActiveRecord .. i think.

    That's a good idea!

    When I actually start writing some code, I'll post my experience with it.

    Yes, please do so.

    I'm going to mark this discussion as resolved. Don't hesitate to re-open it, if need be, or to start new discussions, if you have other questions.

    Ondina

  4. Ondina D.F. closed this discussion on 15 Oct, 2013 12:28 PM.

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