For illustration purposes let us say I'm building a simple blog application and have a class called Blog:
Class Blog(){
__constructor(){
connectToDatabase();
}
}
Class BlogPost($id) extends Blog {
public $title;
public $body;
etc.
}
The blogpost class can be instantiated as an object representing a particular blog post. But when I want to list all the records in the database I have to put that function somewhere else.
I could put it in the Blog class, but assuming I have many, many such functions that don't apply to a particular object, where should I put them?
Or maybe I'm writing a line to a log file. It seems silly to have a 'logfile' class containing a single function that writes a passed string to the text file.
Is it best practice to lump them all in some Utility() class, or should I create several classes such as util_commenting(), util_archives()? Just where should I store all those little stand-alone functions?