定义:
将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示,同时可以分步的构造每一部分。
看起来比较抽象,也不知道具体是什么意思?下面我举一个例子,通过代码来看看什么是建造者模式

举例:

public class ImageBean {  
    private int id; //图片id  
    private String path;    //图片路径  
    private long size;  //图片大小  
    private String type;    //图片类型  
   
    public ImageBean() {  
    }  
   
    public ImageBean(int id, String path, long size, String type) {  
        this.id = id;  
        this.path = path;  
        this.size = size;  
        this.type = type;  
    }  
   
    public int getId() {  
        return id;  
    }  
   
    public void setId(int id) {  
        this.id = id;  
    }  
   
    public String getPath() {  
        return path;  
    }  
   
    public void setPath(String path) {  
        this.path = path;  
    }  
   
    public long getSize() {  
        return size;  
    }  
   
    public void setSize(long size) {  
        this.size = size;  
    }  
   
    public String getType() {  
        return type;  
    }  
   
    public void setType(String type) {  
        this.type = type;  
    }  
}  
View Code

相关文章:

  • 2021-08-05
  • 2021-04-24
  • 2021-12-02
猜你喜欢
  • 2021-05-10
  • 2021-12-20
  • 2021-10-04
  • 2021-05-20
  • 2021-05-10
相关资源
相似解决方案