Re: Is it normal?
From: H. S. Lahman (h.lahman_at_verizon.net)
Date: 04/08/04
- Next message: Tsolak Petrosian: "Re: Composite. Again!"
- Previous message: Shayne Wissler: "Re: The Failure of OOP"
- In reply to: Vijay Singh: "Re: Is it normal?"
- Next in thread: Ilja Preuss: "Re: Is it normal?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 08 Apr 2004 16:56:28 GMT
Responding to Singh...
>>It's not *abnormal*. I don't happen to like classes that hold objects
>>by value. I'll do it on occasion, but I prefer that objects be held
>>through pointers.
>>
>>class A {};
>>class B {private:A* a;};
>>class C {private:B* b;);
>>
>>The reason I prefer this is that b.h does not have to #include a.h,
>>and c.h does not have to #include b.h. They can be written using
>>forward declarations. This speeds up compilation and breaks
>>dependencies.
>>
>
> How will do that in languages like Java. Creating interfaces?
The distinction can't be made in the declaration because it will always
be a reference. However, the distinction can be handled properly in the
way the reference is set and used by others. If others besides the
containing object need to collaborate with the referenced object
directly, the reference should be treated like a referential attribute.
That is, it is set as if it were a knowledge attribute via a setter in
the container's interface (or it is set by the constructor). Similarly,
when an external client initiates a collaboration, it accesses the
reference via a getter and then addresses its collaboration message to
that reference.
Java removes a lot of foot-shooting related to dereferencing and
facilitates garbage collection. It also makes it easier to write code.
But that convenience also encourages a bad habit: passing object
references in message data packets. That practice essentially
temporarily instantiates a relationship between the receiver and the
passed reference.
The problem with that is that the sender of the message needs to know
about that collaboration in order to send the right reference in the
message. That collaboration is a very personal matter between the
receiver and the referenced object that is <usually> none of the message
sender's business. In effect it creates an unnecessary hierarchical
implementation dependency in the sender's implementation.
Generally the rules and policies for instantiating relationships (i.e.,
determining who the participants are) are quite different than the rules
and policies that trigger collaborations (i.e., determine what's next to
do in the overall solution). If the reference is treated as a static
knowledge attribute we can have that separation because setting the
attribute can be done once in one place. Then the relationship can be
navigated from many contexts many times without worrying about having
the right participants.
*************
There is nothing wrong with me that could
not be cured by a capful of Drano.
H. S. Lahman
hsl@pathfindermda.com
Pathfinder Solutions -- Put MDA to Work
http://www.pathfindermda.com
(888)-OOA-PATH
- Next message: Tsolak Petrosian: "Re: Composite. Again!"
- Previous message: Shayne Wissler: "Re: The Failure of OOP"
- In reply to: Vijay Singh: "Re: Is it normal?"
- Next in thread: Ilja Preuss: "Re: Is it normal?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|