Menu

Returning Objects Created within a Task

Help
Andy
2010-09-14
2013-04-26
  • Andy

    Andy - 2010-09-14

    HI I have been using this with great success so far.
    However there is something that I am not too sure about. I have a task and the associated controllers and view. The purpose of this set of classes is to act as a factory pattern. The task is started and the user is presented with a form that allows them to enter a series of values, depending on what is entered causes one of a number of concrete classes to be created (ie WidgetA, WidgetB or WidgetC).

    This I have done and it all work perfectly well, but what I don't understand is how I can return the created Widget back out to the point where the task was started.  (All the forms are started in a Modal state).

    I am sure I can come up with a means by which I can do this, I am just really interested in the recommended way of doing it.

    Thanks
    Andy

     
  • OVZH

    OVZH - 2010-09-28

    Hi Andy,

    What are the Widgets actually? Are they views? Or some application logic classes?

    The simpliest thing is like this:

    class MainViewController…
        public void createConcreteClass()
        {
                Task.CreatedWidget = this.WidgetsFactory.CreateWidget(View.Value1);
        }

    Regards,

    Oleg Zhukov

     
  • Andy

    Andy - 2010-11-02

    Hi Oleg
    Sorry for the delay in getting back to you. The classes in question here are application classes, but there are a few forms and therefore controls that need to be displayed as the user needs to supply some information for these classes to be created.

    I therefore have a CreateWidgetTask which I start when I need to create a new widget.
    What I was trying to get at was, ordinarily I would have got the OnStart function to return the created widget. However this is not an option, so I was wondering how you would advise I should solve this problem.

    I actually got around this problem by passing the MainTask into the OnStart function. The MainTask has an array of widgets, then if a widget is created it is added to this array. This works very well but I was wondering what your suggestions would be.

    Thanks
    Andy

     
  • OVZH

    OVZH - 2010-11-04

    Hi Andy,

    Well. All you need is to return some information from the task. Passing the main task itself (as you do) is a possible solution. But the cleaner design is to introduce a parameter object of a new class.

        class CreateWidgetTaskParam
        {
            public Widget CreatedWidget { get; set; }
        }

    Then you would call

        TasksManager.StartTask(typeof(CreateWidgetTask), new CreateWidgetTaskParam())

    And finally you would use the passed parameter object to return the created widget.

    It's cleaner solution since there'll be no extra dependency to the MainTask class. But you'll need to write the CreateWidgetTaskParam class, so it's always a trade-off :)

    Regards,

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.