Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active July 2, 2024 09:14
Show Gist options
  • Save trikitrok/a7350aece1c42be892c54a31f629091e to your computer and use it in GitHub Desktop.
Save trikitrok/a7350aece1c42be892c54a31f629091e to your computer and use it in GitHub Desktop.
class Address {
private readonly addressLine1: string;
private readonly addressLine2: string;
private readonly city: string;
private readonly state: string;
private readonly country: string;
private readonly postalCode: string;
constructor(addressLine1: string, addressLine2: string, city: string, state: string, country: string, postalCode: string) {
this.addressLine1 = addressLine1;
this.addressLine2 = addressLine2;
this.city = city;
this.state = state;
this.country = country;
this.postalCode = postalCode;
}
getAddressLine1(): string {
return this.addressLine1;
}
getAddressLine2(): string {
return this.addressLine2;
}
getCity(): string {
return this.city;
}
getState(): string {
return this.state;
}
getCountry(): string {
return this.country;
}
getPostalCode(): string {
return this.postalCode;
}
}
class Child {
private age: number;
constructor(age: number) {
this.age = age;
}
getAge(): number {
return this.age;
}
setAge(age: number): void {
this.age = age;
}
}
class Child {
private age: number;
static makeBaby(): Child {
return new Child(0);
}
constructor(age: number) {
if (age >= 4) {
throw new Error("Not a child!");
}
this.age = age;
}
getAge(): number {
return this.age;
}
setAge(age: number): void {
this.age = age;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment