Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

[QUESTION] Why classes use the final modifier #211

@tryvin

Description

@tryvin

Hey Guys,

I'm trying to use llm-chain in a project here, and one thing I keep hitting is the final modifier in classes. Every class here has the final modifier, which makes some things difficult.

For example, right now I'm trying to implement provider usage metadata in the TextResponse class, so I can store how much this request was charged for, and the same applies to basically all *Response classes.

Usually, I would just make my class return an extended version of the base class, for example, I have a Bedrock ResponseConverter class, so, in my convert method, I could just return something like new TextResponseWithUsageMetadata($choices[0]->getContent(), $usageInfo), but unfortunately I can't, as the PhpLlm\LlmChain\Model\Response\TextResponse is marked with final, so I would need to copy the PhpLlm\LlmChain\Model\Response\TextResponse code to my own TextResponseWithUsageMetadata just to add a single property.

The same thing applies to the ChainProcessor in the ToolBox, I needed to change just the processOutput method and had to copy the whole class code to add two lines of code to the processOutput method.

So, my main question is, do we have a strong reason to keep the final modifier in every class? IMHO I see final useful for the "final" user of the code, where you are in total control of your code and you can decide if an XYZ class will remain final or not as the project evolves, but using final in a library which will be used embedded into other projects make the final user life kinda "difficult", as we have to workaround just to add some small features that our projects might need.

Don't get me wrong, I love what you guys are doing here.

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