[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about agent type



>Why, you could just do [$agent info class "Agent/NBD"] which will
>return 1 if $agent derives from Agent/NBD and 0 otherwise.
>
>But the whole idea of tailoring ns-node.tcl (add-target-New) to suit
>this particular nbd agent is a hack.  Maybe a better solution would be
>having a special target function for your object. Something like this
>may work:
>Agent/NBD instproc target {{t ""}} {
>        if { $t == "" } {
>                $self cmd target
>        } else {      
>                $self instvar node_
>                $self cmd target [$node_ set ll_(0)]
>        }
>}
>
>It's a hack too, but at least it doesn't pollute ns-node.tcl with classnames.

I would second this comment.

In ns (or in OO programming in general), explicitly checking the type
of something is almost always not the best way to do things.  For
example, in multicast in ns, for a long time there was code that said
"if the node's target is type X object, do one thing, otherwise do
another".  This code was REALLY fragile; if you pointed the node at
anything else (like a trace object) this code broken, even if the type
X object was just below the trace object.

Exactly what kind of plumbing you're trying to do isn't clear to me
(you binds to Robin, here, if I'm following the thread properly),
but it sounds like you'd be better off pointing your agent where it
wants to go rather than pointing it at the node and having the node
special-case data from you.

   -John Heidemann