As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I have a main class in java which has no attributes and methods. It only contains a main method which calls methods of other classes.
How can I show this class in a UML class diagram?
You should use Association to show this relationship. Association is shown by just connecting two class with a straight line.
If you also want to show the direction of association then you can use directed arrow.
You should question whether you need that class. It doesn't sound like it is performing as an object, instead its a superclass with no meaning within an OO context (ie: it has no meaning within your subject matter, holds no state and performs no actions aside from the main method).
Nothing necessarily wrong with that, but its not considered good practise. I would consider merging that main method into another class that has a meaning within your application.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I want to use Singleton Pattern by this way:
public static final XXX INSTANCE = new XXX();
private XXX() {}
Can you analyse the consequence from the perspective in JVM?
You may run into problems if you have a multi-threaded application. This post may be of assistance. Thread Safe Singleton
Initializing singletons as final static fields is safe. You need to keep in mind that while the construct itself is thread-safe, it does not strengthen the safety of the code within.
Sometimes singletons are the correct solution to a problem, but I would encourage you to stay away from them in general. It makes usually testing harder, if nothing else.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am reading OOPS concepts and got stuck on Abstraction. I am not able to fully understand the concept. As I am feeling that it doesn't belongs to OOPS only. It was also used in C. But how
java abstraction different from C language abstraction. I know it is not a good question
for this forum but i am not able to get the perfect answer.
abstraction means to hide or to separate the complex details of one part of code to other part. say, you have to use a method that does complex calculation, and gives some result. So instead of writing your method inline, its better to write it in a method that just expose the signature (params and return type). in that way your caller (of method) remains unaware of complex code behind the method.
in general, when you use library function in c/c++ or APIs in java, it is also an abstraction.
So indeed, abstraction is not only OOP, but a general concept can be applied anywhere (even beyond the programming).
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
We have a policy that all test classes extend a given test class. The base class sets the JUnit runner to use as well as checking other things about the test class, so not subclassing from it means that other things you're doing wrong aren't going to be checked. (The most serious of these is when there is a category indicating that a test is expensive to run, but because the runner isn't being used, the test will run even for the run-fast-tests build target.)
I figure this is going to involve parsing the Java code, but I can only seem to find parsers for class files. Is there a good parser out there somewhere for parsing Java source?
(This could tie into another question I was going to ask about enforcing use of certain Javadoc tags, since such a parser would surely also parse Javadoc.)
Alternatively is there a DRY way to set a JUnit runner without subclassing? The whole subclassing business is really, really inconvenient.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Let's say I'm extending JFileChooser and making an easy-to-use version, which I'm calling SimpleFileChooser.
It is structured such that it can either be DIALOG_TYPE_OPEN or DIALOG_TYPE_SAVE — hence, JFileChooser's showOpenDialog() and showSaveDialog() methods are superfluous. I replace them with a method called showDialog() which returns a boolean, but this is where I find myself in a dilemma:
Should I override the open/save methods and add #Deprecated tags to
them so that the API user knows they've been superseded? Would that
violate the annotation's original purpose?
Or would a notice in the documentation be enough? If so, where should
this notice be placed: in the class summary or above the overridden
methods? Should I even override the methods in the first place?
Thanks in advance.
I think you are actually building a facade, a simplified version of already existing API. Thus instead of inheritance you should use composition. Hide the original JFileChooser inside your new class and provide simpler API.
As a last resort you can provide public JFileChooser getRaw() method to access wrapped object if some other code needs it.
#Deprecated means you should not use that particular class or method anymore as it will be removed in the future. That annotation is designed for that.
So to answer shortly, if you dont want API users to use the method anymore you should use #Deprecated. Because else you will end up with users that still use methods/classes that you remove in future builds and their projects will be broken when they update.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I need to gather certain information from a method in a (compiled) Java class.
Among other things, I would like to find out all the existing method calls and who is the receiver of each method invocation.
Is there a library for obtaining a convenient representation of a compiled class and its declared methods (something like a DOM view) that can abstract me from interpreting the byte code my self?