Why to make extend exceptions in DAO? [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I was reading up this code review questions here and tutorial by BalusC. In that I have found that exception classes are extended.
What is the need of it? I read something along the lines of client layer should not know SQLExecption but I am not sure I understand it.
Could you reason why to make specialized exceptions? What if my DAO method does not have throws and the client code is in a try-catch.?

Because DAO could be today throw SQLException tomorrow if you want to change DAO layer to write to File, it might result in FileNotFoundException, So hiding underlying stuff you show to your client what matters to them (custom business sensible Exception)

Related

What is the best way to name a class that does some processing only after post construct? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have a ValueObject and a builder class in Java . For example Request.java and RequestBuilder.java. RequestBuilder is used to build Request object. When the Request object is constructed I want to call some business logic which has to to be in separate file. This Request object is constructed at many places in the code and I want to call the businness logic( sets/updates some values on Request object) What is the best way to do and name that class? Would RequestFactory.java be appropriate name for it?
Name it something like RequestProcessor. Don't forget to restrict access to its constructor(s) (private, protected or package which best suits your needs). RequestFactory is more appropriate alternative name for your RequestBuilder.

Calling original method in overloading [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Is it a good practice to overload method in Java, calling this original method inside a new one but passing some default values as parameters for original method?
As the commenters noted, this is a standard practice. Typically, it is used to allow simplified signatures in order to provide default values. Like any other, pattern, some thought should be taken to avoid abusing it.

Difference between class declaration [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
What's the difference between declaring a class inside of another class and declaring a class in a separate file?.
Literally, nested classes were added to Java for two reasons:
1. Source code clarity.
2. Name-conflict reduction.
Java actually didn't need to support doing this, but they were totally doing programmers a "solid" because I'm sure they know how messy code can get when you're in the moment of it all.
To answer your question, explicitly: The difference is that there really IS NOT a difference, it just makes code easier to read and you end up with less name-conflict mistakes.

Where to handle exception whether in DAO layer or Delegate layer? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
For better designing application:
Where to handle exception whether in DAO layer or Delegate layer?
Which one is better approach out of 2 given in 1?
As usual with "design" questions: It depends.
In general, I would say handle as many exceptions as possible locally, in this case in the DAO, but you may want to re-throw some exceptions or raise new ones directly.
E.g. if your DAO causes an SQLException, you do not want to let your upper layers even know that SQL is used, so catching this exception early on would be advisable (so you don't have to import SQLException in your Delegate Layer's package). However, re-throwing the SQLException inside a MyCustomDAOException will allow to retain the error information.
tldr; In the DAO, and throw new Exceptions containing the original one if needed.

Proper convention for blocks of code in Java [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I may be stupid for asking this but... I don't know if I should format blocks like this:
public void elbow() {
System.out.println("Elbow");
}
or:
public void elbow() {
System.out.println("Elbow");
}
or are both correct?
Both are correct. It is a matter of preference. Most guys I work with like to be able to see more code on a single screen so opt for the first, within reason.
You may also mix them if you have a long loop it may be good to place whitespace at your own discretion to improve readability.

Categories

Resources