yiisoft / view

Yii view rendering library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
56 stars 44 forks source link

using "final" keyword on class definitions #175

Closed Slayer911 closed 2 years ago

Slayer911 commented 3 years ago

Now all the classes of this package has keyword "final", what is the idea of this? For example class "Theme" must provide theme path searching, why "BaseView" locked only for these realization of class, instead of accepting interface ? And here you locked the last chance of logic customization by "final" key. Also "WebView" has the same restriction. What the way changing some of them, without fork? Class with more than 1000+ lines, is not flexible

vjik commented 3 years ago

Are there cases when the current functionality is not enough and you need inheritance or an interface for extension?

terabytesoftw commented 3 years ago

well the idea is to use composition if you need to extend but to put a final class to everything with immutable properties.

terabytesoftw commented 3 years ago

@Slayer911 Can you provide a code example of what you are trying to do, thanks.

Slayer911 commented 3 years ago

I am not using the implementation of the class as a service declaration, instead I am using interfaces because only the method contracts are important. That's why i need to extend WebView and adding interfaces : class WebView extends YiiWebView implements TemplateRenderInterface, ViewScriptRegisterInterface. Yes, I can solve this problem by class wrapper, but it's not about the composition, but about workarounds

Also I would like to change the default position of script registering on registerJs method to WebView::POSITION_READY. To do this now, I need to create Proxy class and define all the methods from the WebView there. These are crutches.

And in the case when the programmer encounters an error in this package, he needs to be fixed as soon as possible, but he does not have this opportunity without forking the package. Merge request doesn't merge as quickly as want.

As for the "theme" in my case, this is not so important, because everyone may need their own logic. I will give an example: You need multiple search-priority themes, this can be useful in cases where you have "original" views for "desktop", themes for "mobile" and other theme "mobile with Christmas decorations", and you need to search for a theme first in the "mobile with Christmas decorations", and when the first search was unsuccessful - in the "mobile" theme.

samdark commented 2 years ago

Overall we're not going to make everyhing non-final so let's have separate issues for when there's additional interface or configuration is needed.