Skip to content

Instantly share code, notes, and snippets.

@tacoberu
Last active April 21, 2020 20:04
Show Gist options
  • Save tacoberu/fdb8769de81ec7a5dd042b2bec6444ed to your computer and use it in GitHub Desktop.
Save tacoberu/fdb8769de81ec7a5dd042b2bec6444ed to your computer and use it in GitHub Desktop.
Zapouzdření objektu.
class Person
{
private String name;
private Address address;
private int age;
public Person(String name, Address address, int age)
{
this.assertName(name);
this.assertAddress(address, age);
this.assertAge(age);
this.name = name;
this.address = address;
this.age = age;
}
public void setName(String val) {
this.assertName(val);
this.name = val;
}
public void setAddress(Address val) {
this.assertAddress(val, this.age); //Člověk mladší devatenácti nemůže měnit adresu
this.address = val;
}
public void setAge(int val) {
this.assertAge(val);
this.age = val;
}
// další metody
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment