Imagine a wooden ship. It's a quite famous ship - Theseus himself used it to return to Athens from Crete. After that Athenians tried to preserve it by replacing decayed planks with new ones. Many years passed and now we can say for sure that every part of the ship was replaced at least once. Is it still the same ship?
The ship of Theseus is a well-known philosophical problem about meaning of identity. In the same time it's the good illustration of some programming concepts. To see that, let's look at original question ("Is it the same ship?") and two most popular answers for it: "no" and "yes".
It's not the same ship
Gottfried Wilhelm Leibniz thought objects are same if they share save set of properties. Which means the ship is not the same as soon an first part is replaced. Which also means "you cannot step into the same river twice". Which also means the ship of Theseus is a value object.
- Identity of ship of Theseus is defined by set of planks it's made of.
- After any plank is replaced it's another ship now.
- Ship should be immutable so you can't call another ship with old reference "the ship of Theseus" by mistake.
- Two ships built with same planks are equal and can be considered as same ship.
Well, last one sounds strange with real world objects. But still you can replace the word "ship" with "value object" and these rules remain true.
It's the same ship
Another point of view is that:
- Ship remains same no matter how many planks you replace.
- Two ships are different even they look same.
This leans to an assumption that ship has something that makes it the same over changes. Philosophers argue what that "something" means but developers don't have such problem. Usually it's ID of an entity the ship is.
Being a philosopher is hard. They use abstractions without clear definition (like the word "same") and then argue about what these abstractions mean. I wish developers didn't make same mistake so often.
And if you want to hear more about identity, check this lesson from awesome Crash Course Philosophy. It's about Batman.