I have a question related to general OOP than specific to a language. I was trying out a simple application (in java) and I was trying to model it like a real world scenario. Wh
For this case, no, because that's the only way to redefine the behavior of an object in a hashing data structure in Java.
For other cases there may be better and worse methods of doing things depending on whether they make sense, for example, if I want to change the order of objects in a queue, I'd prefer to implement a custom Comparator
rather than inherit and override a compareTo
method, especially if my new comparison routine is not "natural" for the objects.
Every design pattern has some cases that it's appropriate for and others that it's inappropriate for.