Definition to a wrapper class

Hi,

I'm creating a class to my SCJD cert impl that has a protected RandomAccessFile reference member. I've designed this member as protected since subclasses really need to access it.

My dilema is that I thought of this class as a wrapper to that member, but, the way it is, classes from the same package can access it too, and I didn't really need/want that. I think of a wrapper as something that really encapsulates something, so...

Am I breaking any rules with the definition of wrapper classes? Does anyone know if any Java class has the same dilema?

thanks in advance,

Tales

[620 byte] By [talesToninia] at [2007-11-27 6:17:15]
# 1

> subclasses

> really need to access it.

Unlikely. I don't think I've *ever* created a protected member variable in 8 or 9 years of writing Java code.

> My dilema is that I thought of this class as a

> wrapper to that member,

I would think the thing being wrapped would be private.

> but, the way it is, classes

> from the same package can access it too,

Yes. Protected access allows classes in the same package to access it.

> and I didn't

> really need/want that.

Then I think you're misunderstanding packages and/o subclassing. A package is a "closer" relationship than a parent/child relationship. It's perfectly natural for classes in the same package to be able to access a protected member. If it's a problem that they're able to access that member, then they probably shouldn't be in that package.

> Am I breaking any rules with the definition of

> wrapper classes?

I'm not sure what the formal definition is--or if there is one--but I think making the wrapped thing non-private does violate the spirit of wrapper classes.

Also, I don't know if it's a good idea for a wrapper class not to be final.

jverda at 2007-7-12 17:29:58 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Thanks a lot for your tips, they were really helpful.See ya!
talesToninia at 2007-7-12 17:29:58 > top of Java-index,Other Topics,Patterns & OO Design...