Welcome back.
In the next video we're going to use properties that don't have a backing field.
And I wanted you to understand what that means and when to use that and when not to use it.
Okay.
So what we have here in our car class, we have our properties model brand as well as is luxury.
Right.
So we have those three properties.
And we also created a private member variables for each of those okay.
And we're using those.
And their name is or how you could call them is also is backing fields.
So this is a backing field for the model property.
And this is a backing field for the brand property.
And sometimes you can get away without having a backing field where you can just use the property.
You don't have to define a backing field whatsoever.
And you would do that if you don't want to modify what should happen when you are getting or setting
that property, okay.
What does that mean?
Well, let's look at it.
So here for our model for example we are using a default property.
So we're not overriding what should happen when we get the property.
We're not overriding what should happen when we set the property for the brand property.
However we have something here.
We have a custom instruction for what should happen when somebody tries to access the brand, and also
a custom instruction for what should happen when we set the brand.
So for that, we need to have a backing field which is our underscore brand member variable.
Okay.
So so we could have gotten away without using this model property here.
Now obviously we get an error here for our model.
But let me quickly show you how that would look like if we were not to use a property model with custom
setters and getters you see here.
So string and model and I could have gotten rid of this line here.
And it works.
So this is the default getter and setter.
We're not overwriting what should happen.
So we're not setting the model here.
We're not doing any of that.
We don't need to do that.
We just have this model which is also a variable, right.
It can hold data.
So this variable model now just has a default get.
And the default set, which just means that it's just going to behave like a normal variable.
We're not overriding how it should be modified whenever we're getting it.
And we're not overwriting how it should be modified when we're setting it.
So that's something we did with the brand, right?
We did modify how we want to treat the brand whenever we're getting it, and we did modify how we want
to treat it when we're setting it.
But for our model, for example, we didn't do that, so we could have gotten away without using a member
variable for the model.
We could have just used the property without the backing field model or underscore model.
Okay, so what are the advantages of using it.
It gives you simplicity okay.
So it reduces the amount of code making the class simpler and more readable when you are doing it.
So now that you know that you could say the same thing about is luxury.
If you look at that, you could have said the same thing about is luxury.
Because if we look at is luxury, it also just gets and sets the value by default.
So we could have also just said prop and then here bool and then here is luxury like so then we don't
need this line here.
However we need to obviously make sure that when we're checking is luxury that we are checking is luxury.
So that we're checking the property here.
So instead of the brand because we're using it there.
Right.
If you recall what we did there.
So the whole point here is that you don't need to have a backing field if you are not manually overriding
what should happen when you get or set the variable.
So you're basically just saving yourself some time.
However, if you want to manually override that, you need to use a backing field like our underscore
brand here.
But we we don't need this is luxury at this point anymore.
But for the brand, we need it because we said specifically we want to have full control over what should
happen with our brand.
Okay.
This also makes our work overall easier, right?
That we don't always have to create these private backing fields of our properties and so forth, right?
But when we actually need them, then we're going to use them.
Okay.
So this is just really a heads up because in the next video we are just going to use standard or default
properties without any backing fields.
This is an example of what we're going to have in one of the next videos.
Okay.
So I just wanted to really make sure that you understand that.
And that's it for this video.
See you in the next one.