Say I have a class Person, which has a method doSomething(). I create a static ArrayList<Person> people, and a method doSomethingToAllPeople() which calls doSomething() for each Person in people. Should I put people and doSomethingToAllPeople() in the Person class or in a different PersonManager class? Does it even matter? Here is some example code:
class Person
{
public void doSomething()
{
//stuff here
}
}
//where should the following code go?
static List<Person> people = new ArrayList<Person>();
for(int i = 0; i < 10; i++)
{
people.add(new Person());
}
static void doSomethingToAllPeople()
{
for(Person person : people)
{
person.doSomething();
}
}
staticplaceholders as little as possible. I'd recommend you create aPersonRepositoryclass with an instance memberList<Person>. Create an instance ofPersonRepositoryand have it manage yourPersonsPersonto be exposed topeople.people(e.g.List<Person>), I'd just pass theList<Person>as an argument to the static methoddoSomethingToAllPeople().