Skip to content

Instantly share code, notes, and snippets.

@softwarebygabe
Created June 22, 2020 18:03
Show Gist options
  • Save softwarebygabe/6f634fdee25e0f18540f3a3b6792f246 to your computer and use it in GitHub Desktop.
Save softwarebygabe/6f634fdee25e0f18540f3a3b6792f246 to your computer and use it in GitHub Desktop.
This is usually the go-to pattern when the amount of object properties increases
type Material = 'wood' | 'brick' | 'steel'
interface HouseOptions {
rooms: number
floors: number
material: Material
}
class House {
private rooms: number
private floors: number
private material: Material
constructor(options: HouseOptions) {
this.rooms = options.rooms
this.floors = options.floors
this.material = options.material
}
}
@softwarebygabe
Copy link
Author

construction

const myHouse = new House({
  floors: 2,
  rooms: 5,
  material: 'wood',
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment