Professional Web Applications Themes

[newbie question] Variable visibility - Ruby

[I do apologize for my bad english] Hello, I'm learning Ruby and I think it is a very interesting way of passing time. I already wrote some programs like an enhanced "hello world", and some other programs a little bit more sophisticated but not much more useful. I now want to build a little project which would be usable in the so-called real world. Let me explain this in the fewest words I can before I speak of my philosophical problems : The purpose of the project is to display and manage a data structure, say a tree, and to ...

  1. #1

    Default [newbie question] Variable visibility

    [I do apologize for my bad english]

    Hello,

    I'm learning Ruby and I think it is a very interesting way of passing
    time. I already wrote some programs like an enhanced "hello world", and
    some other programs a little bit more sophisticated but not much more
    useful.

    I now want to build a little project which would be usable in the
    so-called real world. Let me explain this in the fewest words I can before
    I speak of my philosophical problems :

    The purpose of the project is to display and manage a data structure, say
    a tree, and to disjoint the description of the tree from the way it is
    displayed ([G]UI used, layout, interaction with te end user and other
    things like this). The architecture I thought roughly consist of a manager
    which acts like a master with 2 slaves, the application which manage data
    in respond to manager requests and the the GUI stuff which interacts with
    the end-user.
    A typical example of use is the implemention of a file manager which
    manage a file system hierarchy subset (The display I consider should look
    like the one of a good file manager), the tree might also represent
    dependencies within software packages etc. I think an application which
    use that software to implement a file manager should be able to do it in
    200 lines of Ruby code (including comments but not the full license).

    Thank you for following me so far, here is the point where the problems
    begin (despite the fact that the project is in progress, I already found
    its name "Onx").

    A problem arise when I want the manager and the application objects
    communicate :
    Probably due to my heavy background of assembly and C programmer, I first
    imagine that these 2 objects might interact via an object which is passed
    from the manager to the application object appropriate method to handle
    the request and returned to the manager object with some data inside.

    This object class definition would be (very) roughly like this :

    #
    # The manager feeds req and node, the application feeds cc and msg
    # the array is fed by either manager or application depending on the
    # request
    #

    class OnxRequest < Array

    attr_reader :req :cc :msg :node
    attr_writer :req :cc :msg :node

    def initialize( req = nil, node = nil )

    super

    node = node #
    req = req # request code (edit, delete etc.)

    cc = nil # completion code
    msg = nil # completion message

    # maybe some methods
    ...

    end

    end

    I know it would work, but I don't like it much because the manager has no
    need to write in the completion code, the application has no need to write
    in the request code, and the application programmer has no need to
    spend his time reading the doentation of the methods only used by the
    manager before finding the ones he needs.

    Another way is to define a class for a request object and another for the
    answer, I'm not sure it can solve many things. Maybe another way is to
    change the architecture and envisage something very different. I just
    don't know and this is the reason why I need some help to make a clean
    project design.

    It is probably not a typical Ruby concern, but I shouldn't like to see
    answers to this question in some obfuscating language and there may be
    some possibilities of Ruby to do it cleanly. This is the reason why I post
    in this NG.

    I thank you for the attention you paid to this post.


    Harpo Guest

  2. #2

    Default Re: [newbie question] Variable visibility

    [...] 
    [...] 

    I'm not design expert, but I would call a method on the application object
    for every different request, and return/pass in parameters the needed data.

    You can also do this, if manager and application are different processes,
    using DRb.




    Carlos Guest

  3. #3

    Default Re: [newbie question] Variable visibility

    On Fri, 06 Feb 2004 23:49:54 +0900, Carlos wrote:
     
    > [...] 
    >
    > I'm not design expert, but I would call a method on the application object
    > for every different request, and return/pass in parameters the needed data.[/ref]

    The problem was the number of parameters, with a too long parameter list
    it is sometimes difficult to remember the parameters order.

    I will use your design and group parameters in objects
    All the application object methods will look like this :

    def app_( requestObject, dataObject = nil )

    # examine the request object to know more exactly what to do
    ...
    # eventually read and/or update the dataObject
    ...
    # return status, completion codes, completion and error messages etc.
    replyObject

    end

    .... well ... it was not a typical Ruby question ...
     

    I haven't heard about this, I will have a look at the docs right now
    because I'll soon be concerned by process and machine communication.

    Thank you for your reply.
    Harpo Guest

Similar Threads

  1. Newbie Question - PHP variable not working
    By JD in forum PHP Development
    Replies: 7
    Last Post: June 20th, 01:55 PM
  2. newbie question - store the variable
    By boringguy in forum Macromedia Director Basics
    Replies: 4
    Last Post: April 8th, 12:43 PM
  3. Replies: 2
    Last Post: January 18th, 09:28 PM
  4. Newbie Class variable question
    By Elias Athanasopoulos in forum Ruby
    Replies: 3
    Last Post: October 12th, 08:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139