Re: How to give selective access to the methods in a class?




Eric Sosman wrote:
toton wrote:

Eric Sosman wrote:
[...]
Document can contain as many Headers and Segments as you
choose, but cannot modify them (it does not have access to
their setters). In this way Document resembles ArrayList or
HashSet: its job is to hold things, evict things, dole out
references to things, and tell you whether certain things are
or aren't there, but not to make changes to those things.

Can Document hold reference to an inner class?

Yes. Inner classes are classes.

No, Document is not an ArrayList. It holds exactly one Header, and an
ArrayList of Segment's , and can return Document or an element from
Segment ArrayList ( dont allow to add an element to the ArrayList or
remove, just returns the Iterator) .

I didn't mean that Document *is* an ArrayList or HashSet,
I meant that it is *similar* to those. The similarity I wanted
to point out is that Document's role is to hold on to a bunch of
references to Segments and Headers and Whatnots, but not to make
changes to those things. The methods of Document cannot call the
setters of Segment, because they are private. Document can change
the contents of its ArrayList of Segment references, adding new
ones and evicting old ones, but it cannot make changes to the
Segment instances themselves.

Thats fine... yes it is similar, but implements ArrayList by
composition rather than inheritance.
By the way, Iterator has a remove() method. If you want to
make sure nobody except Document can change the "membership" of
the ArrayList, be sure to derive the Iterator from an unmodifiable
view of the ArrayList and not from the ArrayList itself. See
Collections.unmodifiableList().

Oh! I have already done that. Thanks for the suggestion.
One more question, slightly out of topic.
ArrayList can reserve memory for certain size. I expect that memory is
to reserve only the reference, not the object itself (unlike C++
containers where u can reserve for the cobect itself). How much
effective is this in long run? i.e will JIT make the object contains
side by side? or they will be scattered? (boils down to the question,
array holds the object itself or just the reference ? ) I have a
circular buffer which adds several objects from one end and removes
from other end through out the program. It is preferable if the
ArrayList holds the object itself.
thanks again...
--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxx

.



Relevant Pages

  • Re: dynamic structure for storing/querying intervals
    ... intervals on a line (or, in possibly degenerate cases, just points). ... I'd like to be able to query the structure by providing a range and retrieve all intervals which overlap the query range. ... While succeeding points are inside the search interval, store the points in some intermediate structure, sorted or hashed on their interval object references. ... segment, and moving up one level in the hierarchy you get a line segment that contains all its child segments, with references to the intervals that would otherwise be referenced by /all/ the children, and so on. ...
    (comp.programming)
  • Re: IPC::Shareable Problem with multidimentional hash
    ... it is the references to the hashes: ... since a new shared memory segment is created for each thingy ... > already use Storable to store hash structure. ... It uses Storable to store the top level hash structure. ...
    (comp.lang.perl.misc)
  • Re: How to give selective access to the methods in a class?
    ... Document can contain as many Headers and Segments as you ... references to Segments and Headers and Whatnots, ... setters of Segment, because they are private. ...
    (comp.lang.java.programmer)
  • =?iso-8859-1?q?Re:_Sky_HD_and_ANOTHER_=A310_Add_on_-_Are_They_Having_a_Laugh=3F?=
    ... I bailed out of the Murdoch gravy train about three years ago after a ... 15 minute segment of Sky News contained no fewer than eleven references ... to "just press the red button on your remote control". ...
    (uk.tech.tv.sky)
  • Re: How to give selective access to the methods in a class?
    ... Now I only want to give access some of the class to modify some of the ... otherwise they are immutable) a segment, ... object, which has no setters. ... Similarly HeaderCalculator can create a header and store in the ...
    (comp.lang.java.programmer)