Simplifying methods
We might want two instances of Person
to be able to procreate. We can implement this by writing methods. Instance methods are actions that an object does to itself; static methods are actions the type does.
Which you choose depends on what makes most sense for the action.
Good Practice: Having both the 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.
Implementing functionality using methods
Let's start by implementing some functionality by using methods.
- Add one instance method and one static method to the
Person
class that will allow twoPerson
objects to procreate, as shown in the following code:// static method to "multiply" public static Person Procreate(Person...