A
Andrew Stalker
Guest
I have a need to list the users in my database, but being unfamiliar with OOP best practices I am unsure where to implement the method. So far I have come up with two choices:
My question is really is there a best way to do this, and is there any performance differences. Or is this down to application / programmer choice.
The method may return a collection of generic objects (not necessarily cast as a collection of users). In this instance i would lean to the first method. If i then decided to return a collection of users, I would have thought option two would be better. Furthermore, in future there may be many more methods to get a list of users, which leads me to option 2 again.
If the way to program this is largely opinion based then that would give me an answer along the lines of "It's up to me to decide". If however there was a very good reason to avoid one of these due to performance then that would also be useful to know.
Continue reading...
- Using my existing User class, create a static method to get users User.GetAllUsers().
- Create a factory object to create a static method UserFactory.GetAllUsers()
My question is really is there a best way to do this, and is there any performance differences. Or is this down to application / programmer choice.
The method may return a collection of generic objects (not necessarily cast as a collection of users). In this instance i would lean to the first method. If i then decided to return a collection of users, I would have thought option two would be better. Furthermore, in future there may be many more methods to get a list of users, which leads me to option 2 again.
If the way to program this is largely opinion based then that would give me an answer along the lines of "It's up to me to decide". If however there was a very good reason to avoid one of these due to performance then that would also be useful to know.
Continue reading...