Given a class that is semantically supposed to be an object of a certain type, but also has multiple operations for operating on objects of its own type, what is the best way(pattern?) of organizing the class in this type of scenario? I find this to be a common occurrence when a developer creates objects but is thinking with a procedural mindset.
Example:
Class User { private m_userData; function User() {} function GetUserData() {} function KillAllUsers(){} function MaimAllUsers(){} }
It’s not very clear from your description, but it seems that the ‘KillAllUsers’ and ‘MainAllUsers’ methods are operating on a set of users. I would recommend creating a custom UserCollection that has these methods as instance methods or create them as statics and pass in a collection of users. In modern domain model terms, you’d be dealing with a UserRepository.