Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
not asking the functionality of Collection or the Collections classes in Java. i see this pattern everywhere where you have a class called e.g. "Animal" and another class called "Animals". is there a design pattern into play here or is it just general convention?
1.Collection is not class.
2.design pattern is for solving a certain type of problem. your question has nothing to do with design pattern. it could be a naming convention thing. e.g. guava has Lists, Maps..., however you could name your class as Animal and AnimalUtil, AnimalHelper, AnimalTools whatever You name it as AnimalFactory doesn't mean it applied Factory pattern. Just name.
No specific design pattern here. Collections contains utility methods applicable for collection related classes. Another example is Objects class from jdk 7 that contains utility operations you can perform on any object instance.
Related
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 3 years ago.
Improve this question
please I need help with a theoretical issue in Java SE. Below I detail the information I'm looking for:
Difference between internal interfaces (that is, nested, interfaces within others) and subinterfaces (that is, interfaces that extend from other interfaces, or interfaces that implement other interfaces, is this possible?), and most important, under what circumstances do we use each one? I mean, what do we use them for?
I know that there're internal interfaces, since in the Java API there is, for example, the Entry interface, of the java.util package, which is declared within the Map interface of the same package, Entry is an internal interface of Map. But I don't understand the functionality of these internal interfaces. I'd also like to know what the subinterfaces are for, so that I can distinguish them from the internal interfaces.
Greetings,
F
Nested interfaces are exactly the same as non-nested interfaces.
The only difference is that they're defined inside a class or interface instead of being defined outside, and that their name thus includes the enclosing class or interface name: Map.Entry instead of Entry.
That makes it clear that they are conceptually linked to their enclosing class or interface (i.e. Map.Entry makes it clear that it's an entry of a Map).
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'm struggling with a naming issue. What name would you give to an interface that have just one method with this signature:
public interface ?
{
boolean isAvailable();
}
Many classes in my application can implement this interface.
Not that it really matters, you can rename it any time afterwards, and with current IDEs, it is really easy to type any name using autocomplete...
That said, if you want it short, use Available, if you want it more self-explanatory, use CanBeAvailable.
Given that the word "available" already ends with "-able", I think it's okay to break with the Java interface naming convention and call it Availability. Another approach, suggested in Programmers, is to use the prefix "Can-", in which case you can call your interface CanBeAvailable.
The below are the standards defined for Naming conventions.
Class - Always be a Noun
Interface - Always be an Adjective
Method - should be a verb
So, think of some adjective which describes the purpose of your interface.
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 7 years ago.
Improve this question
Which design patterns are implemented by java.util.Currency, if any?
http://docs.oracle.com/javase/6/docs/api/java/util/Currency.html
I assume this is homework.
While there could be several design patterns at play in the implementation, when you see getInstance, you should immediately think Singleton:
http://en.wikipedia.org/wiki/Singleton_pattern
When the API manual at http://docs.oracle.com/javase/6/docs/api/java/util/Currency.html says:
The class is designed so that there's never more than one Currency
instance for any given currency. Therefore, there's no public
constructor.
You obtain a Currency instance using the getInstance methods.
(emphasis mine), well, you should think Singleton again - it's the Intent given by the GoF for the Singleton pattern, almost verbatim.
Currency uses Factory Method design pattern to create instances of this class. Method getInstance() returns Singleton object per Locale, but Currency itself isn't pure Singleton - there might be multiple instances of this class (for different currencies).
Not sure if that's what you mean, but one way of looking at it would be to say it's singleton design pattern
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 8 years ago.
Improve this question
In many places Java utilizes the approach to have both, for example, Collection and Collections class.
Collection is interface, it defined some methods.
Collections class also provide some method.
Why didn't they choose to place all methods inside the interface?
because the names are too puzzled word. Collection is like Collections.
I know the historical reason. like interrupt() and interrupted() , because java must fit to old version, the methods' names are likely, make developer difficult to write and read.
But the collection framwork must have reason in this way.
For starters, an interface cannot have static methods. Note: until Java 8.
Arguably, some of the static methods of Collections should have been made instance methods of Collection, but that would create a lot of "clutter". Plus, extra work for implementations not derived from AbstractCollection etc.
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
I am having trouble in understanding the meaning of "Abstraction in Java". I googled, and studied books, in those I got two types of definitions.
Choosing necessary properties and hiding unwanted details is Abstraction.
Abstraction is the concept of simplifying one idea to a more general, overhead idea.
I feel above two definitions don't mean same, and are entirely different.
So which is correct one?
I think both your statement have same meaning if you think deeply.
Hiding necessary properties and hiding unwanted details leads you to more general, overhead idea.
suppose Animal is a abstract class we hide the nature of animal and their food habits in abstract class and when we talk about Tiger we introduce all the revelant details,
Abstraction is hiding of data.
Means IF you have a class A which contain 2 variables suppose int id,String name
in which if you want to keep that data protected in your class you will keep
Id as private variable so your variable is not directly accessible outside class.
This way you can approach to handle abstraction in class.