More about methods
I wanted to think of some methods that would apply to a Person
instance that could also become operators like +
and *
. What would adding two people together represent? What would multiplying two people represent? The obvious answers are getting married and making babies.
We might want two instances of Person
to be able to marry and procreate. We can implement this by writing methods and overriding operators. Instance methods are actions that an object does to itself; static methods are actions the type does.
Which you choose depends on what makes the most sense for the action.
Good Practice: Having both static and instance methods to perform similar actions often makes sense. For example, string
has both a Compare
static method and a CompareTo
instance method. This puts the choice of how to use the functionality in the hands of the programmers using your type, giving them more flexibility.