Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

use of access modifiers... how can I do this, this and this question

Thread view: 
Indudhar - 20 Oct 2005 11:35 GMT
Hi Everyone,

Heres the logic.

 objectOfClassA can access methods/variables of objectOfClassB
 objectOfClassB can access methods/variables of objectOfClassC
 And objectOfClassA cannot access methods/variables of objectOfClassC

How can I achieve the above?  What various possibilities do I have?
Which one in your opinion is the best?  Can I just use Inheritence to
implement the logic?  Can I just use access modifiers to implement the
logic?  How can I efficiently use both and other options if any, for
best results?

thanks,

Indu
Roedy Green - 20 Oct 2005 11:56 GMT
>Heres the logic.
>
[quoted text clipped - 7 lines]
>logic?  How can I efficiently use both and other options if any, for
>best results?

Inheritance A -> B -> C won't work.  C private B can't see. C package
A can see.

Putting A in a different package won't work.  It will hide package
methods of C, but will also hide package methods of B. A can see
public methods of B and C though.

You create and interface for B that has only the methods you want A to
see in B.  A politely refrains from direct access to B or C, only
going through interface references implemented only on B.

This does not prevent malicious use of methods, but provides some
control if you stick to the convention.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Thomas Weidenfeller - 20 Oct 2005 12:32 GMT
>   objectOfClassA can access methods/variables of objectOfClassB
>   objectOfClassB can access methods/variables of objectOfClassC
>   And objectOfClassA cannot access methods/variables of objectOfClassC
>
> How can I achieve the above?

Is this homework?

Anyhow. Place B and C in one package, and A in another. Implement C as a
non-public class.

> How can I efficiently use both and other options if any, for
> best results?

Efficiently? Best results? In what respect? Number of lines of code?

/Thomas

Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/

Indudhar - 21 Oct 2005 00:21 GMT
Firstly thank you Roedy and Thomas for your replies.  No this is not
homework, but this is work.  I want to design something like this to
help us at my work.  I want to design three groups of classes.  groupA
<=> groupB <=> groupC  groups talking to each other, but I want to
"programmatically" restrict access for groupA<=>groupC.  We are
designing huge number of classes and 4 of us developers.  We were just
sitting and discussing how we can do that and we had no idea.  The only
way is, tell each of us just not do something like groupA<=>groupC even
though you can.  Our web application uses Spring framework.  Is there
something that we can use in Spring, to help us out with this?
Unfortunately we all are novices in Spring!!  It was recommended that
we use it, and so we are in this together!!!
Patrick May - 21 Oct 2005 09:52 GMT
> We are designing huge number of classes and 4 of us developers.

    This is a red flag.  Why are you designing a "huge number of
classes" up front?  What do you mean by "huge"?  Often this happens
when someone decides to wrap every table in an existing database in
its own class.  There are almost always better solutions.

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc.    | The experts in large scale distributed OO
                        | systems design and implementation.
         pjm@spe.com    | (C++, Java, Common Lisp, Jini, CORBA, UML)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.