From the course: TypeScript: Object-Oriented Programming

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Encapsulation

Solution: Encapsulation

From the course: TypeScript: Object-Oriented Programming

Start my 1-month free trial

Solution: Encapsulation

(upbeat music) - [Instructor] The read only property is perfect for an ID. And considering step three is all about being explicit, I think a public read only ID would make sense. And to be explicit, why be explicit? Well, again, it's all about thinking about what your property and methods are going to be used for and what you want to limit access to. That's really the whole idea here. And when you're explicit like this, it makes you at least think about the access modifiers. I can understand not wanting to have additional code on there that you think is repetitive, but my personal preference is to get you to think about it. And when I work in TypeScript, I always have this setting turned on in my TS line to make sure that people go when they do write this. Especially if you're working with maybe developers who aren't as experienced. Now, a protected property, let's just say we had a date of birth and I'll abbreviate that…

Contents