I'm not english native and I just don't get the sense of that statement. Can somebodey explain the meaning with different words, please.It helps make sure that clients have no accidental dependence on the choice of representation
Thank you.
Moderator: admin
I'm not english native and I just don't get the sense of that statement. Can somebodey explain the meaning with different words, please.It helps make sure that clients have no accidental dependence on the choice of representation
Code: Select all
public class Order{
public ArrayList<Item> items;
public List<Item> getItems(){ return items; }
public void setItems(List<Item> i){ items = i; }
}
Code: Select all
public class OrderProcessor{
public void processOrder(Order o){
o.items.remove(0);
}
}
I understand that encapsulation prevents internal variables from being visible outside. However, how does this avoid name clashes?It helps avoiding name clashes as internal variables are not visible outside.
Code: Select all
class Foo {
int bar;
}
class Test {
public static void main(String[] args) {
Foo foo = new Foo();
Foo foo2 = new Foo();
foo.bar = 10;
foo2.bar = 20;
}
}
Does the confusion mean confusion to future programmers, or are there cases where it will actually cause compile-time errors / exceptions / unpredictable program behaviours?If the field in the super class is not private, it will cause confusion in the subclass code.
Users browsing this forum: No registered users and 29 guests