Skip to content

Instantly share code, notes, and snippets.

@AdelinGhanaem
Last active February 17, 2016 16:05
Show Gist options
  • Select an option

  • Save AdelinGhanaem/59de8f505004016aea3b to your computer and use it in GitHub Desktop.

Select an option

Save AdelinGhanaem/59de8f505004016aea3b to your computer and use it in GitHub Desktop.
package com;
/**
* Created by adelin.ghanayem@cayetanogaming.com on 2/16/16.
*/
public class Address {
private int number;
private String address;
public Address(int number, String address) {
this.number = number;
this.address = address;
}
public int getNumber() {
return number;
}
public String getAddress() {
return address;
}
public void setNumber(int number) {
this.number = number;
}
public void setAddress(String address) {
this.address = address;
}
}
package com;
public class Main {
public static void main(String[] args){
//This sholud be immutable but it is not the cas !
User user = new User("Adelin",true,"123",new Address(1,"some address"));// this btw is ugly constructor it can get even uglier use builder patter to make kinda acceptable !!
user.getAddress().setNumber(2); // Address is change so as User !!
}
}
package com;
/**
* Created by adelin.ghanayem@cayetanogaming.com on 2/16/16.
*/
public final class User {
private final String name;
private final boolean isActive;
private final String userId;
private final Address address;
// can be constructed using this constructor ONLY !
public User(String name, boolean isActive, String userId, Address address) {
this.name = name;
this.isActive = isActive;
this.userId = userId;
this.address = address;
}
public String getName() {
return name;
}
public boolean isActive() {
return isActive;
}
public String getUserId() {
return userId;
}
public Address getAddress(){
return address;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment