title: Setters and getters with composition in Java
body: <p>I have a doubt regarding setters and getters in Java when it gets to using composition instead of inheritance. 
  This doubt came when I was solving a college assignment.</p>
  
  <p>Let's say that I have 2 classes: car and battery. Battery has 3 variables (var1, var2, var3) with the getters and setters.</p>
  
  <p>The car class is something like this:</p>
  
  <pre><code>public class Car {
    private String color;
    private String model;
    private Battery battery;
  
    public Car(String color, String model, Battery battery) {
      this.color = color;
      this.model = model;
      this.Battery = new Battery(battery);
    }
  
    public getBattery() {
      return new Battery(battery);
    }
  
    public void setBattery(Battery battery) {
      this.battery = new Battery(battery.getVar1(), battery.getVar2(), battery.getVar3());
      //or this.battery = battery;
    }
  
  </code></pre>
  
  <p>I know the reasoning for the getter method (since it's related with the references for the object), but what about the setter method?
  I tried looking up in the web along with a Java course at Udemy (from Tim Buchalka), but I haven't seen this addressed.</p>
  
  <p>Can someone help me, please? Thanks!</p>