Java Beans, as far as I know, should always:
However, I am wondering what the convention is for Java beans to implement interfaces like Comparable
? I could leave the java bean pure, meaning absolutely no behaviour, only data, and write a custom comparator-class. Implementing comparable is easier though.
Are there any conventions when it comes to implementing simple common interfaces like Comparable to Java Beans? I cannot find any consequences myself, but it feels like I might breaking some rules, and that there might be something I haven't thought of.
IMHO this question is mostly not about conventions but about the needs.
You are right that separation of bean stuff from any business logic is a good style. I'd add here that this typically a good practice because relationship between your beans and comparators are many-to-many, i.e.
However you are right that writing comparison logic into class itself is less verbose and in some cases preferable. The choice completely depends on the author taste and requirements of the application he/she is working on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With