[newbie question] Variable visibility

H

Harpo

[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 documentation 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.
 
C

Carlos

[...]
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. [...]
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 documentation 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.

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.
 
H

Harpo

[...]
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. [...]
I know it would work, but I don't like it (...)

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.

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_xxx( 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 ...
You can also do this, if manager and application are different
processes, using DRb.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top