LiveWire Peer Support Network

Printable Version of Topic "Access Levels -- protected... !protected enough"

- LiveWire Teen Forums & College Forums (http://www.golivewire.com)
-- (http://www.golivewire.com/forums/support-technical.html)
--- Programming & Application Development (http://www.golivewire.com/forums/forum-211-s-0.html)
---- Access Levels -- protected... !protected enough (http://www.golivewire.com/forums/peer-oaoein-support-a.html)


-- Posted by Whuppee at 10:36 pm on May 28, 2006

This is specifically in regard to Java.  Of course, access levels are present in many languages... but possibly with different uses.  I believe C# may suffer from the same issue I feel that Java is, but I'm not yet familar enough with it to say.

As stated in the title / description.. this isn't so much a question, as an opinion I'd like feedback on.  If anything, I'd love to hear other opinions on this topic.


I'm going to temporarily assume I'm safe in skipping over public and private, believing them to be rather self-explanatory--do let me know if I'm wrong.  I'll be happy to talk about them as well, at request.

Anyway:

I always used protected to mean, "Only this class and/or subclasses of it will have access."

Given the practices I follow, that it worked in the bounds I expected it to, and that I was never informed otherwise.... well, it worked as expected.

At least, until I read that protected also meant, "Anything in the same package."


So, if I don't want something to be public...

But I want subclasses to be able to use it: protected.

Except that I ONLY want subclasses to be able to use it.

I dislike being "forced" to package things in regard to this, rather than in regard to their function.

I would personally love to see two versions of protected.  One that excludes all but subclasses... another that operates as the current one does.


Thoughts?


-- Posted by telomere13 at 10:55 am on May 29, 2006

Actually, there used to be a "private protected" keyword in Java which worked the same way as the C++ "protected" keyword (accessible to inheritors, but not others in a package), but it hasn't existed for quite some time now, presumeably because people didn't find it useful enough.

And for all the people telling the original poster not to post here because it has "crossed the line" and "no one will understand what the hell [he's] talking about," please leave.  Just because you happen to not know something doesn't mean that other people your age aren't allowed to know it, too.


-- Posted by Whuppee at 5:42 pm on May 29, 2006

Ah, thanks for the response.

It's too bad they removed support for that feature... I, at least, would have considered it to have value.

I've come up with a few ways that still somewhat enforce this functionality, but I'm not wild about them.


Also, I've no idea what specific comments were made against myself / my subject matter... and it's entirely possible that those that made them won't even check this thread again, but I'd like to respond to both of them as well as anyone else who might happen to read this:


I love programming.  I love talking about and teaching programming related things.

I partially alluded to this (or meant my statement to, anyway) in my original post when I said that if anyone wasn't clear on what I was going on about that I'd be happy to explain.

Seriously.  Anyone wants me to explain intro programming material, classes, "best practices", encapsulating construction, design patterns, analysis mechanisms, inheritance / abstractions, etc... I'd be quite happy to.

One note, though =P ... I'm not wild about having 500 pages of code mailed to me, asking why it doesn't work.

In any case, if anyone doesn't understand what I'm talking about... or would like me to explain something else... I'll at least attempt to.

I feel I have a lot of valuable things to share, but I have far more still to learn myself.  On some topics, I'm certain this process could be easily reversed... and I would like to see that.

I'd love to be part of turning this community into one where we're all participating in learning and teaching each other.


www.golivewire.com