-
-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extensibility and Flexibility through inheritance #593
Comments
From the linked article:
I like that and I like it if libraries (like this one) are pragmatic 👍 Same e.g. with Laravel, almost no Of course when upgrading such projects you're always at the peril of BC changes but in my experience having tests for this particular code can catch this. I'm using |
I think that The only real use-case i found for |
Well put, can't agree more 👍 |
Good point. But I feel that we need some specific examples from this lib to make this discussion more specific. |
I gathered some statistics on how open/closed the code currently is.
There are 2 final classes (and 5 final test classes). Just on a glance, it seems like we might be able to improve upon the consistency. The usage of access modifier looks somewhat random, although i am sure that thought and care has be put into it. Generally, i see a tendency towards closing the classes for modification, which might be driven by static analysers suggesting such approaches. I am not saying that committing 100% to one certain approach is correct, but rather that it will be useful to normalize an organically grown codebase across some axis. |
In terms of specific examples, i can recall two cases where the closed-ness of classes has made it difficult for me to extend them and i ended up re-implementing most of their logic and duplicating a lot of code.
|
Yeah but sometimes In general, nominal type systems and inheritance are like a rabbit hole where you start with something simple (i.e. I do agree that the pragmatic approach makes sense but I don't want to jump into the IoC madness too. So yeah, it should be somewhat pragmatical - we should identify places where extending things should be enough (like lots of But I suspect it won't work for everything out there. |
Is there an update on this? Did I missed something? Are more methods extendable now? :) Implementing Apollo federation support into laravel lighthouse package is not possible right now without duplicating the Schema Printer and it's dependencies. This is not really a solution and error prone. |
@renepardon If there is a specific use case, such as extending the schema printer, you can create a PR for it and make the required methods |
I think the discussion has been had, this issue by itself is no longer actionable. |
This is a continuation of the discussion that originated in #592 (comment). To recap:
This article by Fabian Potencier sums up the point in discussion quite nicely: http://fabien.potencier.org/pragmatism-over-theory-protected-vs-private.html
We can lock everything down to the max, making all classes final and methods preferrably private. This does prevent misuse and keeps the API surface small, but hurts flexibility and extensibility. I personally think this approach makes more sense in large project codebases where you want to keep core components clean and limit technical debt. Libraries don't really have that issue.
The other way would be to keep classes open, allowing extending them and overwriting or calling protected methods. The BC guarantees are only upheld for the parts of the library marked with @api. While this provides some footguns and may cause pain for developers who choose to mess with the insides of this library, i think that this is not really a drawback from a library perspective. It gives more power and responsibility to users of this library.
There is also a middle ground, in which we decide on a case-by-case basis and differentiate between
protected
andprivate
,static
andself
and deliberately usefinal
.I think we should choose consciously, as it is an important design decision.
The text was updated successfully, but these errors were encountered: