4 ms·
Don't extend classes in Java, only implement interfaces. You can go so far as to prohibited extending classes using static analysis tooling.
by plmpsu 4y ago
Don't extend classes in Java, only implement interfaces.
You can go so far as to prohibited extending classes using static analysis tooling.
- chopin 4y agoYou can make them final. This is especially useful when writing libraries.
- plmpsu 4y agoEven better. Or sealed if the usecase applies.
- LecroJS 4y agoNewbie OO q: What’s the benefit/use case of sealing or making an object final? My experience is in javascript so I wonder why I’d ever need something like Object.seal or Object.freeze. Is it really that difficult to maintain object instances that do not change after some point?
- PawBer 4y agoIt's just a tool to enforce the hierarchy in code. Once the codebase gets big it's hard to remember all the details about your API.