There is a simple principle for naming methods in OOP. I’m trying to demonstrate this in the following code — it’s a verb if it manipulates; it’s a noun if it builds. That’s it. Nothing in between. Methods like saveFile()
or getTitle()
don’t fit and must be renamed and refactored. Moreover, methods that "manipulate" must always return void
, for example, print()
or save()
. Let’s take a closer look!