When you first start learning to play a string instrument, the fingerings are often given to you. They are either printed in the music, or else your teacher tells you exactly what fingers you should use. Then, you learn that there are often multiple options for which finger and perhaps which string you could use for a given note, and the concept of fingering starts to get a lot more complicated. So how do you know which finger you should use?
The first time a beginner violinist or violist is introduced to this concept of multiple fingers is when they learn that in first position the pinkie can play the same pitch as the next higher string. But often, there is a "4" in the music when you are supposed to use your fourth finger in the beginning. Beginners tend to find using the pinkie to be uncomfortable, so they try to start treating these 4s and optional and just play open strings all the time.
However, in other keys and positions, the open string isn't an option, and you don't want to be lacking in fourth-finger skills when you get to that point. Also, if the fourth finger isn't used, the student tends to curl it into their hand or tuck it down between the neck of the violin and their palm to keep it out of the way. If you do that, then you will later have to retrain your pinkie to stay over the fingerboard. I did, as a beginner. Trust me, it's a very frustrating experience that you would rather avoid. It is therefore important that you don't avoid using your fourth finger.
When should you use your fourth finger instead of an open string?
Well, that depends on who you ask.
Some will vaguely say to use whatever is most efficient.
Others will say you should play open going up and fourth going down but never cross a string for only one note.
Then, there are people who hate the brighter sound of open strings, especially A and E, and will say that you should absolutely never play an open string unless the sheet music indicates otherwise.
If I'm deciding fingerings for myself instead of a student and it's not for an ensemble in which someone else might have a say, I usually choose the fingering that requires the least number of string crossings. But sometimes I want that open string sound, and sometimes I really don't, and sometimes I want to shift up to third so I can use my middle finger to get a wider vibrato than what my pinkie will allow.
I tell my students to do whatever the person responsible for making the call says (teacher, conductor, section leader), and meanwhile I will help them develop a concept of what is most efficient for them so that someday they can choose their own fingerings when there is no one to tell them what to do.