Objects Without Behaviour

后端 未结 4 956
庸人自扰
庸人自扰 2021-01-25 11:35

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

4条回答
  •  滥情空心
    2021-01-25 11:53

    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.

提交回复
热议问题