Questions tagged «builder-pattern»


11
有效Java中的构建器模式
我最近开始阅读Joshua Bloch撰写的Effective Java。我发现构建器模式[本书中的项目2]的想法非常有趣。我试图在我的项目中实现它,但是有编译错误。本质上,以下是我想做的事情: 具有多个属性的类及其构建器类: public class NutritionalFacts { private int sodium; private int fat; private int carbo; public class Builder { private int sodium; private int fat; private int carbo; public Builder(int s) { this.sodium = s; } public Builder fat(int f) { this.fat = f; return this; } public …

11
IntelliJ中的生成器模式代码生成
有什么方法可以自动在IntelliJ中编写Builder模式? 例如,给定这个简单的类: class Film { private String title; private int length; public void setTitle(String title) { this.title = title; } public String getTitle() { return this.title; } public void setLength(int length) { this.length = length; } public int getLength() { return this.length; } } 有没有一种方法可以让IDE生成此代码或类似代码: public class FilmBuilder { Film …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.