How to code properly | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to code properly

Hi, in my practicing with different classes, I have a doubt, when you need to perform a check or operation, do you do it in the class that you create for your objects, or in the main class? I explain with an example, if I create a class car, and it have an Id with 9chars, should I check that the minimum chars are correct in main or in the car class?

30th Jan 2017, 11:22 PM
Ivan T. Espinosa
Ivan T. Espinosa - avatar
2 Answers
+ 3
i would create a 3rd Class in your example - a validator class. i use model classes only for proprties, getter and setter. normaly i have a package validator with all kinds of validation classes, or a package called utils or helper wher i have helper classes for this kind of code. but thats only "my" style of coding ;)
31st Jan 2017, 12:04 AM
R4xx4r
R4xx4r - avatar
0
thanks for your answer @R4xx4r I have another question. Do you create in that third class the methods for validations as static? I recently studied static and I think I understood it, but I don't know is this situation could be the optimal for use it.
31st Jan 2017, 2:30 AM
Ivan T. Espinosa
Ivan T. Espinosa - avatar