Should I @ omit the superclass method?

Let's say I extend JFileChooser and create an easy-to-use version that I call SimpleFileChooser .

It is structured so that it can be DIALOG_TYPE_OPEN or DIALOG_TYPE_SAVE - hence the JFileChooser showOpenDialog() and showSaveDialog() methods are redundant. I am replacing them with the showDialog() method, which returns a boolean, but this is where I am in the dilemma:

Should I override the open / save methods and add @Deprecated tags to them so that the API user knows that they have been replaced? Will this violate the annotation of the original purpose ?

Or would the documentation notice suffice? If so, where should this notice be placed: in the class summary or above overridden methods? Should I even redefine methods first?

Thanks in advance.

+4
source share
2 answers

I think that you are actually creating a facade , a simplified version of an existing API. Thus, instead of inheritance, you should use composition. Hide the original JFileChooser inside your new class and provide a simpler API.

As a last resort, you can provide the public JFileChooser getRaw() method to access the wrapped object if it needs some other code.

+8
source

@Deprecated means you should no longer use this particular class or method, as it will be removed in the future. This annotation is intended for this. Therefore, to answer shortly, if you do not want API users to use this method more, you should use @Deprecated. Because otherwise you will end up using users who still use methods / classes that you remove in future assemblies, and their projects will be violated when they are updated.

+1
source

Source: https://habr.com/ru/post/1444209/


All Articles