文章由浅入深,先用简单例子说明建造者,然后分析模式的优缺点,最后结合优秀开源框架Mybatis,说明该模式的用处。
1、先定义一个机器人模型
package com.jstao.model; public class Robot { private String head; private String body; private String hand; private String foot; public String getHead() { return head; } public void setHead(String head) { this.head = head; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } public String getHand() { return hand; } public void setHand(String hand) { this.hand = hand; } public String getFoot() { return foot; } public void setFoot(String foot) { this.foot = foot; } }