Java Beans: What am I missing?

前端 未结 5 1945
别跟我提以往
别跟我提以往 2021-02-07 06:08

I\'m wondering if I\'m missing something about Java Beans. I like my objects to do as much initialization in the constructor as possible and have a minimum number of mutators. B

5条回答
  •  梦谈多话
    2021-02-07 06:32

    I share the idea that minimize the mutability is a good thing. As already pointed out, the advantage of JavaBeans is that they are easy to handle by the frameworks.

    To get the best of "both worlds", I think that a good option is to use the Builder pattern, slightly modifying the Builder to comply with the JavaBeans standard. So, if you need a framework functionality that requires that your class comply with the JavaBeans standard, you can use the Builder instead the actual class.

提交回复
热议问题