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

Discussion in 'Java' started by Indudhar, Oct 20, 2005.

  1. Indudhar

    Indudhar Guest

    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
    Indudhar, Oct 20, 2005
    #1
    1. Advertising

  2. Indudhar

    Roedy Green Guest

    On 20 Oct 2005 03:35:51 -0700, "Indudhar" <> wrote
    or quoted :

    >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?


    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.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Oct 20, 2005
    #2
    1. Advertising

  3. Indudhar wrote:
    > 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


    --
    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/
    Thomas Weidenfeller, Oct 20, 2005
    #3
  4. Indudhar

    Indudhar Guest

    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!!!
    Indudhar, Oct 21, 2005
    #4
  5. Indudhar

    Patrick May Guest

    "Indudhar" <> writes:
    > 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.
    | (C++, Java, Common Lisp, Jini, CORBA, UML)
    Patrick May, Oct 21, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shila
    Replies:
    3
    Views:
    671
    Tor Iver Wilhelmsen
    Feb 24, 2004
  2. Tony Morris

    Local Classes - Access Modifiers?

    Tony Morris, Jan 14, 2006, in forum: Java
    Replies:
    10
    Views:
    920
    Stefan Schulz
    Jan 16, 2006
  3. man4*.*

    access modifiers

    man4*.*, Nov 18, 2006, in forum: Java
    Replies:
    4
    Views:
    353
    man4*.*
    Nov 19, 2006
  4. TimeHorse
    Replies:
    4
    Views:
    276
    Bruno Desthuilliers
    Oct 23, 2007
  5. Miquel

    Class & modifiers modifiers

    Miquel, Jan 25, 2007, in forum: Ruby
    Replies:
    4
    Views:
    160
    Miquel
    Jan 26, 2007
Loading...

Share This Page