Calling complex methods: statically or after new instance?

I don’t know if I have worded the subject well so let me just show examples. I want call a method (or a function) that will do a lot of complex stuff. In procedural style I would do this:

log_changes($old_obj, $new_obj);

or placing the function in a static class for better organization:

Utilities::log_changes($old_obj, $new_obj);

This function will do a lot: compare two objects (db table rows), compare all objects related to them and comparison of each object type has to be done differently and then written in the database - the important thing is there will be a lot of code, too much to cram into one function without sacrificing readability. So logically I want wrap all of this in a class so I can have separate components in methods. Then the call would look like this:


$changes = new ChangeDetector($old_obj, $new_obj);
$changes->log();

While this will work well it looks to me like it’s a bit too much. This class will have a very simple interface - just one method callable from the outside. Every time I would have to create a new instance. Now some will say what’s the problem with that - the problem is that instantiating a class for everthing would be tedious. For example, imagine all php built-in functions needed an instance:


// instead of list($first_name, $last_name) = explode(' ', $full_name);
$a = new Explode;
list($first_name, $last_name) = $a->explode(' ', $full_name);

// instead of $n = substr($title, 0, 20);
$a = new Substr;
$n = $a->substr($title, 0, 20);

Creating instance for every function would just not make a lot of sense - at least not to me. So far, when I needed a simple function I simply made a static method in a utility class:

$new_str = Utils::indentLines($str);

But when I wanted to implement something more complicated, I used an object:

$indent = new IndentLines($str);
$new_str = $indent->getIndented();

But now I see inconsistency in my approach: who is to decide if the implementation is complex enough to make it into a live object? Certainly not the one making the call from the outside. If I want to call Utils::indentLines($str); I should simply type Utils::indentLines($str); and not care if its underlying implementation is complex or not. The method indentLines() should be bothered about the complexity, not the calling code. I’d like to resolve this incosistency. On the other hand, if I use a class that needs instance then my code is not consistent with most of php functions that do not need instances.

I hope I have expressed myself clearly enough. I am talking about cases when:

  1. I need an object to implement a task - not because I need to provide multiple methods to the outside world but only because I want to organize the implementation into separate components (private methods).

  2. The object would have only one public method, because it offers to perform only a single task.

  3. The object instance would not be necessary for anything after calling its only public method.

What would you suggest? Use a static method or method on a live object? Or maybe wrap all components into a static class? Or always use a static method for calling the method but call an external class if complexity gets high? Like this:


class Utilities {
  static public function log_changes($old_obj, $new_obj) {
    $changes = new ChangeDetector($old_obj, $new_obj);
    $changes->log();
  }
}

class ChangeDetector{
  public __construct($old_obj, $new_obj) {
    // ...
  }

  // all the complex code goes here into various methods
  // ....
}

Utilities::log_changes($old_obj, $new_obj);

Here the static method log_changes() would decide whether the implementation would be just a few lines inside itself, or a separare object should be instantiated and called. Any ideas?