Skip to main content
class A {
    B bObject;
    
}

class B {
    private List<SomeType> list;
    public List getList() {return list;}
    public void foo(int i) {
       list.get(i).someTypeMethod(); // 2 dots
    }
}   

class SomeType {
    public void someTypeMethod() {}
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

class A{
    B bObject;
    
}

class B{
    private List<SomeType> list;
    public List getList(){return list;}
    public void foo(int i){
       list.get(i).someTypeMethod(); // 2 dots
    }
}   

class SomeType{
    public void someTypeMethod(){}
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

class A {
    B bObject;
}

class B {
    private List<SomeType> list;
    public List getList() {return list;}
    public void foo(int i) {
       list.get(i).someTypeMethod(); // 2 dots
    }
}   

class SomeType {
    public void someTypeMethod() {}
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

added 155 characters in body
Source Link
user4205580
  • 423
  • 1
  • 5
  • 11
class A{
    B bObject;
    
}

class B{
    private List<SomeType> list;
    public List getList(){return list;}
    public void foo(int i){
       list.get(i).someTypeMethod(); // 2 dots
    }
}   

class CSomeType{
    public void someTypeMethod(){}
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

class A{
    B bObject;
    
}

class B{
    private List<SomeType> list;
    public List getList(){return list;}
}   

class C{
    
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

class A{
    B bObject;
    
}

class B{
    private List<SomeType> list;
    public List getList(){return list;}
    public void foo(int i){
       list.get(i).someTypeMethod(); // 2 dots
    }
}   

class SomeType{
    public void someTypeMethod(){}
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

deleted 1 character in body
Source Link
Carra
  • 4.3k
  • 27
  • 28
class A{
    B bObject;
    
}

class B{
    privaateprivate List<SomeType> list;
    public List getList(){return list;}
}   

class C{
    
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

class A{
    B bObject;
    
}

class B{
    privaate List<SomeType> list;
    public List getList(){return list;}
}   

class C{
    
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

class A{
    B bObject;
    
}

class B{
    private List<SomeType> list;
    public List getList(){return list;}
}   

class C{
    
}

Suppose I want to call get on the list from bObject in class A. Should I simply call getList().get(3), or maybe it's better to rewrite a method in the B class that retrieves or adds the element at the specified position from/in the list?

In general, if class B field wasn't a List, but some other class C, should B prevent class A from calling C methods directly?

Source Link
user4205580
  • 423
  • 1
  • 5
  • 11
Loading