Basically, creating a Dogs
class provides you with additional layer of indirection.
This means that all your other code will reference (i.e. use) only the Dogs
class, but not the internal list. This, in turn, means that whenever you decide to switch from using list to, say, using plain arrays internally (or to change Dogs
's implementation in any other way, for that matter), you can readily do so.
That's a motivation for it. As for the question of it being 'better', that depends strongly on whether you can limit usage of the internal container by a stable Dogs
's API. If you can, creating a Dogs
class is justified. Otherwise, it's simpler and easier to just go ahead and use List
.
One example of the aforementioned 'stable API' is an application of the Visitor pattern. In this case, the Dogs
class shall have a single visit()
method accepting a visitor argument. A visitor 'knows' how to process a Dog
, but is completely unaware of the Dogs
internal structure. Which is a good thing.