Note that there are some explanatory texts on larger screens.

plurals
  1. POredoing object model construction to fit with asynchronous data fetching
    primarykey
    data
    text
    <p>I have a modeled a set of objects that correspond with some real world concepts.</p> <p>TradeDrug, GenericDrug, TradePackage, DrugForm</p> <p>Underlying the simple object model I am trying to provide is a complex medical terminology that uses numeric codes to represent relationships and concepts, all accessible via a REST service - I am trying to hide away some of that complexity with an object wrapper.</p> <p>To give a concrete example</p> <p>I can call</p> <pre><code>TradeDrug d = Searcher.FindTradeDrug("Zoloft") or TradeDrug d = new TradeDrug(34) </code></pre> <p>where 34 might be the code for Zoloft. This will consult a remote server to find out some details about Zoloft. I might then call</p> <pre><code>GenericDrug generic = d.EquivalentGeneric() System.Out.WriteLine(generic.ActiveIngredient().Name) </code></pre> <p>in order to get back the generic drug sertraline as an object (again via a background REST call to the remote server that has all these drug details), and then perhaps find its ingredient.</p> <p>This model works fine and is being used in some applications that involve data processing.</p> <p>Recently however I wanted to do a silverlight application that used and displayed these objects. The silverlight environment only allows asynchronous REST/web service calls. I have no problems with how to make the asychhronous calls - but I am having trouble with what the design should be for my object construction.</p> <p>Currently the constructors for my objects do some REST calls sychronously.</p> <pre><code> public TradeDrug(int code) { form = restclient.FetchForm(code) name = restclient.FetchName(code) etc.. } </code></pre> <p>If I have to use async 'events' or 'actions' in order to use the Silverlight web client (I know silverlight can be forced to be a synchronous client but I am interested in asychronous approaches), does anyone have an guidance or best practice for how to structure my objects.</p> <p>I can pass in an action callback to the constructor</p> <pre><code> public TradeDrug(int code, Action&lt;TradeDrug&gt; constructCompleted) { } </code></pre> <p>but this then allows the user to have a TradeDrug object instance before what I want to construct is actually finished. It also doesn't support an 'event' async pattern because the object doesn't exist to add the event to until it is constructed.</p> <p>Extending that approach might be a factory object that itself has an asynchronous interface to objects</p> <pre><code> factory.GetTradeDrugAsync(code, completedaction) </code></pre> <p>or with a GetTradeDrugCompleted event?</p> <p>Does anyone have any recommendations? Does anyone know how the new Reactive framework might fit in with any solution?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload