Closed ghost closed 7 years ago
I've submitted a PR #42
Inheritance promotes tight coupling, final
is a mean to avoid it by encouraging clients to use composition/aggregation instead of inheritance. Could you please elaborate on your particular use case? Can it be solved by composition?
I have an adapter class that makes a resource for a 'portfolio'. Using composition, I cannot pass this class to the Document
as it doesn't implement the correct interface.
I was using inheritance to follow the Liskov substitution principle, as it is valid that my extension, or the base class, could be used interchangeably (granted the base class wouldn't set up the resource correctly, but hey).
I understand the argument about tight coupling, but as this is an adapter using interfaces in my system anyway, it's not a big issue in the context it's being used in.
I've jigged it to be a builder class for now.
I use final in code myself, but not in code used as packages for other systems as I find it too restrictive. It's my opinion though :)
Thank you a lot for the feedback. I don't like ResourceObject
in its current state, tbh. Mostly because of its mutability. As you see, the API is still at v0, so it's sort of unstable. For v1 I am considering making it immutable converting setters setFoo()
into something like withFoo()
which would produce another object. So it'll become a complete value object.
Cool. As this is now part of my API work at work, I may get involved in that as time allows. Sometimes mutability is a good thing, and sometimes it isn't. I'll get more up to speed with the project layout.
Closing as the PR was merged. Thanks! :)
I am implementing a presentation pattern that was to extend the
ResourceObject
to build a resource for specific parts of my application, apart from it uses thefinal
class keyword.Is it really a requirement to limit developer ingenuity by using
final
in the library?Would it not be better to allow developers to make use of the classes available with inheritance?