Re: Using iterators and efficiency.

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


Date: Thu, 22 Jan 2004 22:29:25 GMT

Responding to Harris...

This is a classic case of getting sidetracking because the only context
is an existing solution rather than the actual problem to be solved.

> h.lahman@verizon.net (H. S. Lahman) wrote (abridged):
>
>>>The problem is that different subnodes have different
>>>representations. Some use a linked list, some use arrays. You have
>>>suggested 2 implementations, but neither will handle both kinds of
>>>subnode.
>>
>>This assumes there are collections nested within collections.
>
>
> No. It just takes the problem as the original poster said:
>
> I have two types of node that contain lists of other nodes,
> their representation internally is different.

Right; two simple collections with different collection management
mechanisms in their /implementation/. Note that this description says
nothing about there being different types of Nodes.

Given the overloading of 'node' in the description, the only thing that
makes sense here is:

        0..1 R1 1
[List] -------------------- [Node]
    | 1 | *
    | R2 |
    +---------------------------+

where, in the set of all Node instances, two instances have lists of
specific Nodes.

>
>
>
>>The OP postulated two simple collections, each with its own iterator.
>
>
> Yes, close enough. The two simple collections are in subclasses of the
> TrieNode class. A client of TrieNode does not know what kind of subclass
> he has, so doesn't know what kind of iterator to create.

But TrieNode is irrelevant to my solution. The client needs to navigate
the lists of Nodes via the R3 -> R2 relationship:

[Client]
   * |
     |
     | R3
     |
     |
   2 | 0..1 R1 1
  [List] -------------------- [Node]
     | 1 | *
     | R2 |
     +---------------------------+

The issue is how Client talks to List over R3 (i.e., indirectly through
an iterator or directly via a simple List.getNext). If there is a
different problem to solve that /requires/ Node to be subclassed, that's
fine. But this was the problem originally described.

[However, even if Node is subclassed, it doesn't make any difference to
how List is accessed by Client -- that subclassing is a matter between
Node and List.]

Recall that my initial question was whether iterators were needed at
all. Change the R3 multiplicity to

[Client]
   1 |
     |
     | R3
     |
     |
   2 | 0..1 R1 1
  [List] -------------------- [Node]
     | 1 | *
     | R2 |
     +---------------------------+

and both iterators and my solution are superfluous.

[BTW, I also see no reason why the client navigating the collection
should be creating it. That is usually symptomatic of poor cohesion in
the abstractions. Generally the rules and policies for participation in
a collaboration are quite different that the rules and policies for the
execution of the collaboration. (Factory and related patterns provide
exactly this sort of separation of concerns.) So it is rather uncommon
for either class participating in a collaboration to also be responsible
for instantiating the relationship. (A noteworthy exception <sometimes>
being whole/part.)]

*************
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

  • 40iPlay C/S audio player/recorder
    ... iPlay also works fine for CDs, ... Order of the main list can be by: load order (e.g., playlists load in ... long lists (iPlay Client handles up to 40,000 files -- a size which can ...
    (microsoft.public.pocketpc.multimedia)
  • Re: UML "OR" Composition Question
    ... if within this library direct instances are created/used. ... one adds N subclasses of N+1 subclasses. ... all instances of [Avian] indifferently because there are no subclasses. ... the Client is indifferent to which Avian instance is ...
    (comp.object)
  • Re: Data validation dependent lists
    ... This ensures that only related selections can be made. ... I select client Joe then select JoeJob1. ... There are 3 vehicle types ... dependent lists are working fine). ...
    (microsoft.public.excel.misc)
  • Re: outlook 2003 public folders of custom list
    ... I am not clear on whether the Client Contact List folder is in a user's ... Sue Mosher, Outlook MVP ... > DDS4 20/40GB internal TBU with Veritas Backup Exec Power ... > prefer to backup all lists along with that days tape ...
    (microsoft.public.outlook.contacts)
  • Idempotent ODBMS iterators
    ... the database in the same state as it would if the operation had ... almost all of the operations I had designed were idempotent. ... my implementation requires that the client ... A map iterator, which is itself always stored as an object ...
    (comp.lang.java.programmer)