Re: How to give selective access to the methods in a class?
- From: "toton" <abirbasak@xxxxxxxxx>
- Date: 9 Aug 2006 07:24:21 -0700
Eric Sosman wrote:
toton wrote:
Eric Sosman wrote:
[...]Can Document hold reference to an inner class?
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.
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 toOh! I have already done that. Thanks for the suggestion.
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().
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
.
- Follow-Ups:
- Re: How to give selective access to the methods in a class?
- From: Eric Sosman
- Re: How to give selective access to the methods in a class?
- References:
- How to give selective access to the methods in a class?
- From: toton
- Re: How to give selective access to the methods in a class?
- From: Eric Sosman
- Re: How to give selective access to the methods in a class?
- From: toton
- Re: How to give selective access to the methods in a class?
- From: Eric Sosman
- How to give selective access to the methods in a class?
- Prev by Date: J2ME: where is its data base files?
- Next by Date: String Array Manipulation
- Previous by thread: Re: How to give selective access to the methods in a class?
- Next by thread: Re: How to give selective access to the methods in a class?
- Index(es):
Relevant Pages
|