Making collections public is quite a bad idea. While encapsulating fields is important in any case, collections are even more important.
The collection itself is usually not an object you actually care about. So the caller of your class shouldn't be able to set it, replace it or even take it away (say: set to null
). It should only care about the items in it. If you make it possible to set the list instance from the outside, you risk that several instances of your class share the same list instance. This will have some nasty side effects.
Your class is responsible (at least) to create the list instance to make sure that it is a dedicated list and never a null reference.
Exposing the list by a public getter is actually like fully exposing it. This is the minimal encapsulation you should do, it is actually like no encapsulation at all.
Full encapsulation is done by only exposing the items as IEnumerable
and provide Add, Remove, Count and similar operations in separate methods or properties. The more you need, the more it gets complicated. It is useful if you really don't need many basic operations from the outside and manage as much as possible within the class.