mindplay-dk / sql

Database framework and query builder
Other
18 stars 6 forks source link

Refactor BoolType #43

Open mindplay-dk opened 6 years ago

mindplay-dk commented 6 years ago

BoolType supports a public factory-method get() and implements a fly-weight pattern, which seems to imply you could use this to generate a custom BoolType instance, on the fly, for a specific column.

That doesn't work in practice - the column factory-methods in Table only accept a class-name string, which means that all types must be registered up front.

Perhaps that's not a bad thing - explicitly defining types up front has the expected performance characteristics and avoids implementing a fly-weight pattern and/or manually registering types under some other name besides the class-name.

Suggestion:

Remove get get() factory-method, and make the BoolType constructor public.

Keep the default true, false arguments as-is.

This will make it easy to extend BoolType into a custom BoolType, which is in fact already possible with e.g.:

class MySQLBoolType extends BoolType
{
    public function __construct()
    {
        parent::__construct("1", "0");
    }
}

Lets remove the confusing/misleading factory-method though.