Calling original method in overloading [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 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.

Related

How come java.time.Duration is immutable? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
The Duration class is following the immutable pattern. In general I try to avoid object regeneration for resource reasons. I have learnt about the immutable concept and it is quite controversial IMHO. How come this special decision to introduce the immutable pattern especially for the Duration class?

is "get" the right prefix for a service's method that queries a DB? [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 1 year ago.
Improve this question
I'm writing a method that given a product, returns for each country the number of sales. I named it getNumOfSalesByCountry().
To me, the word "get" relates to a getter of a bean and not to a function that makes a query to a DB.
Can you suggest better names? (Or you think the name is valid)
Thanks
You can name it something like retrieveNumOfSalesByCountry(), but I think getNumOfSalesByCountry() is good too.

Which Design pattern should i use to maintain pre initialized set of objects? [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 6 years ago.
Improve this question
I have some pre initialized objects of some class. These objects are heavy weight objects and each correspond to some configuration options specified by user. There will be exactly one instance corresponding to one configuration and same will be used every time.
My question is, which design pattern suits best to handle this kind of situation?
Most likely a Flyweight is what you are looking for. https://en.wikipedia.org/wiki/Flyweight_pattern
This can be used for pre-initialise heavy weight objects and reuse them.

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.

Why do we need static methods in interfaces Java 8? [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 8 years ago.
Improve this question
Why? Isn't this kind of anti-pattern?
This makes it easier for you to organize helper methods in your libraries; you can keep static methods specific to an interface in the same interface rather than in a separate class.
Please read this

Categories

Resources