[#1816] Ruby 1.5.3 under Tru64 (Alpha)? — Clemens Hintze <clemens.hintze@...>

Hi all,

17 messages 2000/03/14

[#1989] English Ruby/Gtk Tutorial? — schneik@...

18 messages 2000/03/17

[#2241] setter() for local variables — ts <decoux@...>

18 messages 2000/03/29

[ruby-talk:01820] Re: Objects nested sometimes.

From: Dave Thomas <Dave@...>
Date: 2000-03-14 15:25:19 UTC
List: ruby-talk #1820
Hugh Sasse Staff Elec Eng <hgs@dmu.ac.uk> writes:

> 	sort of thing?  I'm just a bit unsure about the instance
> 	variables in both types -- I know I can make them public with
> 	attr() but that creates *functions* to access them[?], so will 
> 	that mean that the port cannot point to the parent's variables,
> 	or not?  I will have several nodes and several ports, so it
> 	must be the case that the voltages (for a node or a port) are
> 	not shared across all instances of the same type (node or
> 	port).  Hence my question about instance variables.

Well, I guess I'd probably ask "why do you want to point to your
parent's variables in the first place".

It seems to be me are two scenarios:

1. You need the values of the voltages *at the time* the node is
   created. In that case you'd want to copy the parent's values down.

2. You need the *current* values of the parent's voltages. In that
   case, why have an extra set of instance variables in the child, as
   you can always get to the parent's values when you need to?

However, there is a third point. There's an OO design principle,
somewhat imperiously called The Law of Demeter, which basically says
you shouldn't go groveling around inside sub-objects, because it
increases coupling in your code, making it more difficult to
maintain. In this case, we have a Node, that contains a number of
Ports. The LOD would say that

      v = aNode.getPort(1).getVoltage(2)

is bad form, because you're asking a sub-object of Node (a Port) to do 
something. The LOD says it would be better to hide the implementation
of Ports within Nodes by doing something like:

     v = Anode.getPortVoltage(1, 2)

Now, I'm not particularly trying to push the Law of Demeter here--I
break it every day. However, sometimes, when things start to get all
tangled, it can help point the way towards simplifications. Perhaps
the problems you're having are not with the storage of data, but with
its access?

Now I know absolutely nothing about your problem, so this may be just
a load of bollocks. Please ignore it if so ;-)


Regards


Dave

In This Thread