Skip to content

Better naming of implementations#13

Description

@mecha

Even as the original author of most of the classes in this package, I've often found myself annoyed at how they are named 馃槄 We could easily improve this using class aliases.

The proposal that I outline below stems from this viewpoint: the names should reflect what the services are. For instance:

[
    // message IS a value
	'message' => new Value('Hello'),

    // greeting IS an alias
    'greeting' => new Alias('message'),

    // username IS a global var
    'username' => new GlobalVar('username'),

    // BUT ...

    // logger is ... a constructor??
    'logger' => new Constructor(Logger::class),

    // alert_text is a ... string service??
    'alert_text' => new StringService("{0}, {1}!", [
        'message',
        'username',
    ]),

    // render_fn is a funky what??
    'render_fn' => new FuncService(['message'], function (string $message) {
        return $message;
    }),
]

It would be great if all the classes had more sensible names that better outlined what the services are, rather than what the service definitions are.

I've prepared a list of which classes I think could use a better name, along with my proposed alias names:

Current name New Alias name
Constructor Instance
FuncService Callback
StringService TemplatedString

These proposed names will help to make service definitions look more natural and declarative.

[
    // logger IS an instance
    'logger' => new Instance(Logger::class),

    // alert_text IS a templated string
    'alert_text' => new TemplatedString("{0}, {1}!", [
        'message',
        'username',
    ]),

    // render_fn IS a callback
    'render_fn' => new Callback(['message'], function (string $message) {
        return $message;
    }),
]

While we're at it, we could also alias the ArrayExtension class to ArrayPushExtension, in preparation for the new ArrayMergeExtension to create a clearer distinction between the two.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions