[Ns-developers] A question about downcast netdevice pointer.
craigdo@ee.washington.edu
craigdo at ee.washington.edu
Thu Sep 25 12:34:55 PDT 2008
> In my reply, I was simply pointing out the other workable way
> but not prescribing it. If this is considered ns-3 best
> practice (e.g., users SHOULD dynamic_cast but MAY GetObject),
I think this is wrong. If we are going to pronounce a best practice, I
think GetObject should be that practice since it does not require knowledge
of how the underlying aggregation is implemented to work.
Consider the following: if I have an aggregation that consists only of a
C++ inheritance tree, dynamic_cast works. However, if I want to add another
object via aggregation, I cannot get to that object by dynamic_cast, I must
use GetObject. It seems exactly the wrong thing to do to require knowledge
of the implementation of an Object aggregation by the client. Why should I
change my approach based on an implementation when GetObject works in both
of those cases?
But in the Seattle meeting, we decided this is a matter of style and there
would not be a prescription; we decided we would solve this issue by
documentation.
The real problem here is that we never solved the problem by documentation.
This is not the only place where the interface/object relation is unclear.
My canonical example was Ipv4Impl which introduced yet another level of
confusion. Someone I know started a long, long, long discussion about this
in the Seattle meeting.
> I will try to document it somewhere, and maybe we accept the
> above patch once tested?
There used to be a big section in the manual called "Object Model" to
address this, but that section been deleted and gone stale (see other.texi).
I think the answer is to revive that and explain what the conceptual model
is and how it works. Also we need to document that, for example,
CsmaNetDevice presents itself to the world as an aggregation of Object,
NetDevice and CsmaNetDevice and one can maneuver around these using
GetObject without having to understand how the model author decided to
implement it all and use C++ cast operators.
As we decided in Seattle, "read the code" is not a good enough answer.
-- Craig
More information about the Ns-developers
mailing list