Question: I would like to know what is a more appropriate way to code in Java. Is it generally better to pass entire objects in the method's parameters or just using the fields from the class?

1. Using the field:

```
public class Dictionary {
    ArrayList<Definition> list;

    public Dictionary() {
        this.list = new ArrayList<Definition>();
    }

    public void newEntry(String key, String value) {
        this.list.add(new Definition(key, value)); 
    }
}

```

```
public class SampleTests {
    @Test
    public void Tests()
    {
        Dictionary d = new Dictionary();

        d.newEntry("Apple", "A fruit");
    }
}

```

2. Passing an object:

```
public class Dictionary {

    public Dictionary() {
        //this.list = new ArrayList<Definition>();
    }

    public void newEntry(String key, String value, ArrayList<Definition> list) {
        list.add(new Definition(key, value)); //I'm not using field from this class!
    }
}

```

```
public class SampleTests {
    @Test
    public void Tests()
    {
        Dictionary d = new Dictionary();
        ArrayList<Definition> list = new ArrayList<>();

        d.newEntry("Apple", "A fruit", list);
    }
}

```

I've checked this related [question](https://softwareengineering.stackexchange.com/questions/319376/do-you-generally-send-objects-or-their-member-variables-into-functions?newreg=0b1a563e3ce04b6a80d3fc271287c344), but the guys' answers do not help me much

Answer: 
Option 1, without question.

The whole point of your `Dictionary` class is to encapsulate the list and any other information you need to make your dictionary work. You already have access to the class's fields, so passing them as parameters is pointless.

Your Option 2 exposes the internal details of your class, defeating its purpose.
In real life, very often you don’t just add an entry to a list, but it has consequences. Like an application could be displaying the entries of a list, and adding something needs to trigger a whole sequence of events. If you tell the object to add an item, it can take care of everything. If you insert an item yourself into the list, that can have negative side effects. And if not know, then next year.