+ 1

Naming conventions

If you have a class called Car public class Car{ } How do you name properties of this type the private variable can be _car private Car _car; the public part would be public Car xxx { get; set; } Would is on the place of the xxx I would like to put Car on the place of the xxx. But you can't because you named your class already Car. Is there a naming convetions for this situations or a good practice ?

3rd Apr 2018, 7:23 PM
sneeze
sneeze - avatar
8 Réponses
+ 2
Good solution Have good memories on delphi and pascal who had every type named Txxx like TCar. If a view is a xxxView a viewModel is a xxxViewModel can a Car be a CarModel ?
3rd Apr 2018, 8:29 PM
sneeze
sneeze - avatar
+ 2
Then, I think that in this case 'Car' fits perfectly as a property name. But still, if you don't want to use it, you may write 'OwnedCar' instead.
4th Apr 2018, 9:03 AM
Mante
Mante - avatar
+ 1
I did hesitate because I was afraid it is confusing but may be it is not confusing at all
3rd Apr 2018, 8:01 PM
sneeze
sneeze - avatar
+ 1
Yes I understood that. Your solution is a good solution which will make the code more clear and easy to read. But I am the designer, of the Car-class and also the designer of the classes that have the properties. I am at the beginning of a new project, so I can choose good naming conventions now and benefit from it in the years to come.
3rd Apr 2018, 8:43 PM
sneeze
sneeze - avatar
+ 1
I'd say it depends on what's the purpose of that variable. You may call it CarInstance, Instance or something like that. If you tell us what you're using that variable for, than we may suggest you a better name
3rd Apr 2018, 9:50 PM
Mante
Mante - avatar
+ 1
https://code.sololearn.com/cBIXfeZ17hxl This is what I want to make. Just a object with another object inside I like my type-names to be simple So Car would be the perfect naming for a object that defines a Car but I also like to use it for the property name Just assume that every person has one Car. Then Car would be perfect naming for the property that defines this persons Car Console.WriteLine(Person1.Car.Brand);
4th Apr 2018, 8:29 AM
sneeze
sneeze - avatar
+ 1
Thanks
4th Apr 2018, 9:04 AM
sneeze
sneeze - avatar
+ 1
Will keep that in mind. Thanks rudolph
4th Apr 2018, 9:23 AM
sneeze
sneeze - avatar