• BuilderParttern(建造者模式)


    /**
     * 建造者模式
     * 主要用于构造复杂的对象
     * 在优朋播放器就是采用建造者构建的,可以说比较有心得吧
     * @author TMAC-J
     *
     */
    public class BuilderPattern {
    	/**
    	 * 要构建的对象bean
    	 * @author voole
    	 *
    	 */
    	public class Person{
    		
    		private String sex;
    		
    		private String height;
    		
    		private String weight;
    		
    		private String hobby;
    
    		public String getSex() {
    			return sex;
    		}
    
    		public void setSex(String sex) {
    			this.sex = sex;
    		}
    
    		public String getHeight() {
    			return height;
    		}
    
    		public void setHeight(String height) {
    			this.height = height;
    		}
    
    		public String getWeight() {
    			return weight;
    		}
    
    		public void setWeight(String weight) {
    			this.weight = weight;
    		}
    
    		public String getHobby() {
    			return hobby;
    		}
    
    		public void setHobby(String hobby) {
    			this.hobby = hobby;
    		}
    	}
    	
    	interface IBuilder{
    		
    		void buildSex(String fale);
    		
    		void buildHegith(String height);
    		
    		void buildWeight(String weight);
    		
    		void buildHobby(String hobby);
    		
    		Person buildPerson();
    	}
    	
    	public class PersonBuilder implements IBuilder{
    		
    		Person person;
    		
    		public PersonBuilder() {
    			person = new Person();
    		}
    
    		@Override
    		public void buildSex(String fale) {
    			person.setSex(fale);
    		}
    
    		@Override
    		public void buildHegith(String height) {
    			person.setHeight(height);
    		}
    
    		@Override
    		public void buildWeight(String weight) {
    			person.setWeight(weight);
    		}
    
    		@Override
    		public void buildHobby(String hobby) {
    			person.setHobby(hobby);
    		}
    
    		@Override
    		public Person buildPerson() {
    			return person;
    		}
    		
    	}
    	
    	public void test(){
    		IBuilder personBuilder = new PersonBuilder();
    		personBuilder.buildHegith("我柯一米五!!!");
    		//后面同上
    	}
    	
    }
    

      

  • 相关阅读:
    如何稳定地使用 Google 搜索https://encrypted.google.com/
    widows 2008 同步时间命令
    MySql 初始化权限脚本
    [转] windows下Svn服务器之必须提交修改注释篇
    给编译好的DLL增加签名
    Anychart 破解备注
    Javascript 日期时间格式正则
    微服务项目规范(二)
    微服务项目规范(一)
    mac系统安装、启动与关闭redis
  • 原文地址:https://www.cnblogs.com/yzjT-mac/p/6226976.html
Copyright © 2020-2023  润新知