Hierarchy of classes

Discussion in 'Plugin Development' started by Fl1pzta, Jul 12, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Fl1pzta

    If I have 3 classes, one instantiating the next, what would be the best way for the third class to access the first class. For example,

    Code:
    Class1:
    public Class1(){
    new Class2(this);
    }
    public String sayHello(){
    return "hello";
    }
     
    Class2:
    private final Class1 class1;
    public Class2(Class1 class1){
    this.class1 = class1;
    new Class3(this);
    }
     
    Class3:
    private final Class2 class2;
    public Class3(Class2 class2){
    this.class2 = class2;
    [B]What's the most efficient way of accessing sayHello() from Class3?[/B]
    }
     
  2. Offline

    JoshArgent

    Fl1pzta I believe this is the best method:
    Code:
    this.class2.class1.sayHell();
    
     
  3. Offline

    Fl1pzta

    That's what I'm thinking, but is there any other way? Maybe better?
     
  4. Offline

    nisovin

    Pass the Class1 instance through to the Class3 instance? You can have more than one parameter on a constructor you know.
     
Thread Status:
Not open for further replies.

Share This Page