Skip to content

Static Classes #3

@tomjn

Description

@tomjn

I'm seeing classes defined that will never be turned into objects and are acting as pseudo-namespaces, e.g. the Tools class. This would be better as a namespace with pure functions as it is not object oriented programming.

As a general rule objects have state and represent things, the object oriented way of doing this would look more like this:

interface Form_Input { display() }
class Text_Input implements Form_Input { ... }
class Number_Input implements Form_Input { ... }


$input[] = new Text_Input('value', 'name' );
$input[] = new Text_Input('value', 'other name' );
$inputs[] = new Number_Input(12, 'number name' );

foreach ( $inputs as $input ) {
    $input->display();
}

Here each input is represented by an object, and there are multiple objects, with a shared interface. Just because it's a class doesn't mean it's OO, especially if you're then using static methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions