If I have a User and I want that user to Register, is it better to have a Registration class with a Register method that accepts a user or is it just good enough to have a User object that has a Register method
public class Registration
{
public void Register(User user)
{
}
}
public class User
{
public void Register()
{
}
}
What are the advantages of doing it one way over the other?
The way I’d look at it is to think in terms of real life objects. Is a ‘Registration’ an object, a real ‘thing’? Probably not.
The real ‘things’ you have in this scenario are the User, and the thing they’re registering with (I’ll assume you’re talking about a website, for example).
So – I’d probably create an object which represents the thing the user is registering with – ‘Site’, for example, and add a Register method on that.