I have a class (say class A, with A.h and A.m files). This class needs a utility class, and I’m too lazy to create Utility.h and Utility.m
Is there a way to include its definition (implementation) in A.m? Is it unavoidable to create its declaration (interface)?
What are the best practices in this case?
Of course there is a way: just add the implementation to the file. The compiler doesn’t care where your implementation is, as long as it has all relevant declarations at hand. Its the linker’s job to sort out where the object code actually is.
And no, you cannot avoid creating a definition. So create it where ever your other code needs it. If you need the helper class only for class A then you should prefer putting the interface declaration into the implementation file, too.