0

Let's say I have a user class in my application. In the back end of the site in the administration section the admins are able to see a list of all registered users and edit their information.

How should I load all the user objects? Right now I have a static function in the user class that returns an array populated by user objects.

That probably isn't the correct way to do it? What is the correct way to load a bunch of objects? What terms or patterns should I Google for more information? Should I have a LoadUsers class? If so, wouldn't it just have a single method? Would that be overkill?

Shane
  • 827
  • 8
  • 18
  • to answer that you'd need to provide the structure of your current user class. But don't cause this is not a code review site. There's nothing wrong with a class that has only one purpose if it is what makes sense to you and it works. You could also attach that method to a general user class that also handles specifics for a single user. Just make sure you properly protect it. – Kai Qing Apr 10 '14 at 17:12
  • So are you saying a static class User::LoadAllUsers() doesn't violate any OOP guidelines? What do you mean by properly protect it? Thanks. – Shane Apr 10 '14 at 18:48
  • See here: http://stackoverflow.com/questions/8795651/when-to-use-static-classes-in-php - properly protect it means that you describe this as an admin panel utility. User class may be used publicly all over the place. If your user list is only used by admins I just mean that you should make sure only admins can access this method. That's all. – Kai Qing Apr 10 '14 at 18:54
  • Thanks! Put all this in answer so I can give you points :) – Shane Apr 11 '14 at 14:31

0 Answers0