Is bad practice returning the data structure of member functions in a composition?

Take, for example, you have class A and class B. Class A uses a composition type relation that interacts with many objects of class B. Class A has saved references to objects of class B in Arralist

Class A { ArrayList<B> beeObjects; } 

Is it really bad practice to return the data structure of an array list if you want to implement functionality that interacts with objects in an arraylist?

+4
source share
1 answer

Not at all. You can very well return your beeObjects ArrayList and use it. In fact, in Object Orient Programming you would like to do the usual practice if you have a genuine use case.

+1
source

Source: https://habr.com/ru/post/1445932/


All Articles