Re: Is it normal?

From: H. S. Lahman (h.lahman_at_verizon.net)
Date: 04/08/04


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



Relevant Pages

  • Re: AOP beginner
    ... and execute a code fragment before/after the ... In both cases one has a binary relationship between classes and a collaboration between a client and service where the client navigates a relationship to address a collaboration message. ... in OOPLs there are exactly three ways to implement a 1:1 relationship: via pointer; by passing an object reference to a method; or by providing a Find search mechanism based on explicit object identity. ... In addition, once one decides which implementation to use, there is exactly one way to instantiate the relationship for each implementation: supply an address for a pointer variable; provide an object instance as a method argument; and add an object to the collection managed by a Find. ...
    (comp.object)
  • Re: space travel or war
    ... policies that they thought were in the long term best interests of the ... See the reference above... ... World oil production is 83 million barrels per day. ... Iraqi oil production is less than 2 million barrels per day. ...
    (sci.space.policy)
  • RE: How to design Security Policies
    ... There are many sites that have such policies, ... with classification & labeling suitable for your business sector. ... A good reference book to have for outlining roles and responsibilities ... We are in process of designing the security policies for entire ...
    (Security-Basics)
  • Re: list of group policys
    ... Perhaps the best reference from MS on the security ... policies is found in the W2k3 Security and Hardening Guides. ... > Group Policy Settings Reference for Windows Server 2003: ...
    (microsoft.public.windows.group_policy)
  • Poll for users: mac_partition and mac_ifoff policies
    ... I'm currently in the process of reviewing the use of the MAC Framework in FreeBSD, following meetings at the developer summit about proposed simplifications and enhancements. ... One of the on-going concerns I have had is that several of the policies we ship are reference implementation policies, ... While mac_stub and mac_test are both extremely useful for devleopers as shipped, it's not clear to me that mac_ifoff and mac_partition offer significantly similar value, and as they are reference policies rather than production policies, my leaning is to provide them as downloads on the TrustedBSD web site and via p4, but to not ship them with FreeBSD 7.0. ...
    (FreeBSD-Security)