Last active
February 17, 2016 16:05
-
-
Save AdelinGhanaem/59de8f505004016aea3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 !! | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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