Welcome back.
In this video, I just wanted to quickly show you that there is also something called a computed property.
Now what is a computed property?
A computed property is a property that is computed based on values of other properties.
So it does not store a value itself, but it always depends on other properties values.
So in this case the area will always be the width times the height.
So whenever you want to get the area you're just going to have a return width times height.
You cannot set the area because we didn't define what should happen when we try to set the area.
So let's have a look at what this looks like when we are actually accessing the area here.
So you don't have to use the same code.
You don't have to write this code or whatever.
I just wanted to quickly show you that there are these things called computed properties.
So now let's say we create a rectangle and R1 which is going to be a new rectangle.
Right.
And I can now set R1 dot width to be let's say five and r1 dot height to also be five.
So then let's use console right line and say area of R1 is and then whatever the area is.
So R1 dot area okay.
So now let's run this and we will see the area of R1 is 25.
Now if I wanted to override the area directly.
So R1 dot area is equal to five.
You see that wouldn't have worked because we never defined a setter for this property.
So property or index or rectangular area cannot be assigned to it is read only.
So suddenly this becomes a read only because if we look at it, it only has a getter.
It doesn't have a setter.
So if you have a getter only then it becomes a read only.
So read only property.
Okay, if you only have a setter then it becomes a write only property.
Okay, so here is an example of a read only property that at the same time is also a computed property
which which doesn't store a value itself.
It always just gives gives you a value when you are accessing it.
And how does it give you the value?
By doing some calculations based on other values that you have, or based on other properties that you
have.
So there you have an example of computed properties.
And also by the way, you see that we didn't even define a constructor for our rectangle because it
just assumes that you have or that you want to use the default constructor which does nothing.
So you see here we could create a new rectangle without even having a constructor that works as well
by the way.
Okay, so that's it for this video.
See you in the next one.