tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/765-migrate-mobile-app-to-rl-enabled-mobiile-appRobotlegs: Discussion 2018-10-18T16:35:35Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/126122512012-01-03T18:04:07Z2012-01-03T18:04:07Zmigrate mobile app to RL enabled mobiile app<div><p>Hi Corey,<br>
The short answer is, you can ‘go through each view and change
to use RL’,</p>
<ul>
<li>
<p>if you built the Views using a modular approach, meaning they
could run separately without problems as if they were a separate
application</p>
</li>
<li>
<p>if you don’t have business logic and domain logic in your
Views</p>
</li>
<li>
<p>if your Service classes are reusable and well encapsulated</p>
</li>
<li>
<p>if you can easily identify and separate the domain logic from
the rest of your app</p>
</li>
<li>
<p>if you can provide the Service classes with an
eventDispatcher</p>
</li>
<li>
<p>if you can easily mock a service call</p>
</li>
</ul>
<p>You can even create a Context for each View/functional area, if
you wanted to.</p>
<p>Anyway, it doesn’t matter which framework you’d use
and which patterns you’d apply, the first thing to do would
be to identify the tiers and layers of your application and to
separate the logic pertaining to each tier. I’d start with
the Services, Models and Views, because they are the parts that
should be reusable, more or less.<br>
I have identified about 6 main functional areas in your
application: Home, Hosts, Reports, Facts, Groups, Info (from the
screenshots). Interesting application, btw.<br>
So, start with Home and build it as a separate app using robotlegs.
See if it has any dependencies on other Views or other parts of
your app, and make HomeMediator responsible for the communication
with them.</p>
<p>If you need a more detailed answer, you’ll have to give us
more details about what you want to achieve or the issues
you’re encountering :)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/126122512012-01-03T18:59:40Z2012-01-03T21:51:19Zmigrate mobile app to RL enabled mobiile app<div><p>Well I do have my code separated as much as I can. Here is what
I have thus for (pre RL)</p>
<p>-- remoteadminlib</p>
<pre>
<code> --- controllers
--- models
--- services</code>
</pre>
<p>-- remoteadmin mobile app -- remoteadmindesktop app</p>
<p>The remoteadminlib is essentially my services layer. It holds
the models, controllers, and some other reusable business logic or
custom components that the mobile and desktop app use.</p>
<p>The views for the most part only interact with the controller,
where as the controller only interacts with the services and
models. I use events from the controller to notify the view as each
controller extends EventDispatcher. The controllers usually have
lots of code to reshape the data or send an event out. The views
usually call some controller method to get data and then listen for
the response from the controller that has the data so they are
decoupled in a way.</p>
<p>The views seem to have more AS code that I would prefer. My
hopes with RL are to remove most of this code and put either in
commands, services, or the mediator. Currently I have all the logic
to write to disk in my view which I would like to move to a
service.</p>
<p>One interesting difference when comparing how DI works and what
I use now is that currently my app holds all the controller
instances in memory via a Dictionary Hash. The instances are
created on first use and then stored. However, my code has snippets
of this controller creation in every view which is kinda messy. My
controllers even have this same code to ensure the other
controllers exist. Many of my controllers have to communicate with
each other which could be a big difference with RL.</p>
<p>Here is an example of code that would go away with RL. Probably
1000 lines worth throughout the app since I have to ensure that
controllers exist before using. Ahhh, I can't wait to get rid of
this code.</p>
<p><a href=
"http://pastebin.com/95i8Wva5">http://pastebin.com/95i8Wva5</a></p>
<p>Two questions I have thus far are the following:</p>
<ol>
<li>Is the mediator only able to talk to the the specific view it
was created for? Can I inject anything else besides models?</li>
<li>Whats the best way of pushing views on the stack along with the
data? Is the Mediator the only way or can I use a command? (I
acutally tried command but couldn't Inject the view so I could not
use the below statement)<br>
view.navigator.pushview(NextView, data)</li>
</ol></div>Corey Osmantag:robotlegs.tenderapp.com,2009-10-18:Comment/126122512012-01-04T16:18:55Z2012-01-04T16:18:55Zmigrate mobile app to RL enabled mobiile app<div><blockquote>
<p>Two questions I have thus far are the following:</p>
<ol>
<li>Is the mediator only able to talk to the the specific view it
was created for? Can I inject anything else besides models?</li>
</ol>
</blockquote>
<p>Actually, I would say that Mediators don’t
“talk”, they “shout” - dispatching events,
on the shared EventDispatcher provided by the framework, to which
interested actors, like Commands and other Mediators, will then
react.<br>
Many analogies have been used to describe the role of Mediators: a
bridge between the View Components and the rest of the application,
a mailman, a switchboard, a secretary, a waiter...<br>
In other words, the Views (Components) should be completely unaware
of the framework and should encapsulate the code specific for
displaying data, user interaction, layout, design. As already
mentioned, no business or domain logic.<br>
The Mediator is a two ways communication channel:</p>
<ul>
<li>
<p>from the View to the rest of the application by dispatching
events ( announcing changes due to user interactions or the need
for some data to be displayed)</p>
</li>
<li>
<p>and from other parts of the application to the View by listening
to events and accessing API methods on the View (data to be
displayed or actions to be performed)</p>
</li>
</ul>
<p>So Mediators just listen for events, dispatch events and access
methods in their Views, letting the Views handle and manipulate the
data.</p>
<p>If you want to <strong>strictly</strong> follow the recommended
practice you should avoid having business or domain logic in your
Mediators. Also avoid using the Mediator as a View Controller or
code behind class. In this light, you should only inject into a
Mediator the mediated View, the events (or Signals) needed for the
communication with the rest of your app, and maybe VOs that
you’d want to pass to the view.</p>
<p>Of course you can inject a Model or even a Service into your
Mediator, if you want to, but make sure that you first understand
the implications of such an approach! Try to understand the Best
Practices and to follow them as much as you can in the beginning.
The moment you are comfortable enough with the framework, you can
easily take the approach that’s best suited for your
needs.</p>
<p>Injecting other Mediators or accessing their methods is
something you really shouldn’t do!<br>
If you want a Mediator (or any other actor) to communicate with
other Mediators let it do it via custom events. Mediators are good
listeners ;-)</p>
<blockquote>
<p>2.Whats the best way of pushing views on the stack along with
the data? Is the Mediator the only way or can I use a command? (I
acutally tried command but couldn't Inject the view so I could not
use the below statement) view.navigator.pushview(NextView,
data)</p>
</blockquote>
<p>The best way, in my opinion, is to let the View (Navigator) push
the views on the stack. The Command should just dispatch an event
with a payload containing the info needed by the Navigator. The
Mediator, listening for that event, would pick up the data and pass
it to the View. For example:<br>
In the Mediator<br>
protected function changeActiveView(event:NavigationEvent):void<br>
{</p>
<p>view.changeActiveView(event.viewClass);<br>
}</p>
<p>In the View<br>
public function changeActiveView(viewClass:Class):void<br>
{</p>
<p>navigator.pushView(viewClass);<br>
}</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/126122512012-01-04T19:14:15Z2012-01-04T19:14:16Zmigrate mobile app to RL enabled mobiile app<div><p>Thanks this helps. I have spent a lot of time this week already
creating RL version on my app. I see the light now and understand
whats going on.</p></div>corey