当前位置: 首页 > news >正文

推销商务网站的途径有哪些建筑公司企业宗旨

推销商务网站的途径有哪些,建筑公司企业宗旨,工程类招聘网站哪个好,宜兴百度推广目录 场景 不用模式实现 代码实现 有何问题 解决方案 代码改造 组合模式优缺点 思考 何时选用 场景 不用模式实现 代码实现 叶子对象 package day14组合模式;/*** 叶子对象*/ public class Leaf {/*** 叶子对象的名字*/private String name ;/**…目录 场景 不用模式实现  代码实现  有何问题  解决方案 代码改造  组合模式优缺点 思考  何时选用 场景 不用模式实现  代码实现  叶子对象 package day14组合模式;/*** 叶子对象*/ public class Leaf {/*** 叶子对象的名字*/private String name ;/*** 构造方法,传入叶子对象的名字*/public Leaf(String name){this.name name;}/*** 输出叶子对象的结构*/public void printStruct(String preStr){System.out.println(preStr _ name);} }组合对象 package day14组合模式;import java.util.ArrayList; import java.util.Collection;/*** 组合对象组合对象里面包含其他的组合对象或者是叶子对象* 由于类型不同需要分开记录*/ public class Composite {/*** 用来记录包含的其他组合对象*/private CollectionComposite childComposite new ArrayList();/*** 用来记录包含的其他叶子对象*/private CollectionLeaf childLeaf new ArrayList();/*** 组合对象的名字*/private String name ;/*** 构造方法*/public Composite(String name){this.name name;}/*** 向组合对象加入被它包含的其他组合对象* param c 被它包含的其他组合对象*/public void addComposite(Composite c){this.childComposite.add(c);}/*** 向组合对象加入被它包含的叶子对象* param leaf 被它包含的叶子对象*/public void addLeaf(Leaf leaf){this.childLeaf.add(leaf);}/*** 输出组合对象自身的结构*/public void printStruct(String prestr){// 先把自己输出去System.out.println(prestr this.name);// 然后添加一个空格表示向后缩进一个空格输出自己包含的叶子对象prestr ;for (Leaf leaf : childLeaf) {leaf.printStruct(prestr);}// 输出当前对象的子对象了for (Composite c : childComposite) {// 递归输出每个子对象c.printStruct(prestr);}} }Client package day14组合模式;public class Client {public static void main(String[] args) {// 定义所有的组合对象Composite root new Composite(服装);Composite c1 new Composite(男装);Composite c2 new Composite(女装);// 定义所有的叶子对象Leaf leaf1 new Leaf(衬衣);Leaf leaf2 new Leaf(夹克);Leaf leaf3 new Leaf(裙子);Leaf leaf4 new Leaf(套装);// 按照树的结构来组合 组合对象和叶子对象root.addComposite(c1);root.addComposite(c2);c1.addLeaf(leaf1);c1.addLeaf(leaf2);c2.addLeaf(leaf3);c2.addLeaf(leaf4);// 调用跟对象的输出功能来输出整棵树root.printStruct();} }有何问题  必须区分组合对象和叶子对象并进行有区别的对待 解决方案 组合模式 定义 思路将组合对象和叶子对象统一起来。通过引入一个抽象的组件对象作为组合对象和叶子对象的父对象这样就统一起来了。 代码改造  抽象父组件对象 package day14组合模式.Component;/*** 抽象的父组件对象*/ public abstract class Component {/*** 输出组件自身的名称*/public abstract void printStruct(String preStr);/*** 向组合对象中加入组件对象* param child*/public void addChild(Component child){throw new UnsupportedOperationException(对象不支持这个功能);}/*** 从组合对象中移出某个组件对象* param child*/public void removeChild(Component child){throw new UnsupportedOperationException(对象不支持这个功能);}/*** 返回某个索引对应的组件对象* param index 需要获取的组件对象的索引索引从0开始* return 索引对应的组件对象*/public Component getChildren(int index){throw new UnsupportedOperationException(对象不支持这个功能);} }Leaf类 继承一下这个抽象类别的没有变化 package day14组合模式;import day14组合模式.Component.Component;/*** 叶子对象*/ public class Leaf extends Component {/*** 叶子对象的名字*/private String name ;/*** 构造方法,传入叶子对象的名字*/public Leaf(String name){this.name name;}/*** 输出叶子对象的结构*/public void printStruct(String preStr){System.out.println(preStr name);} }组合对象类 package day14组合模式;import day14组合模式.Component.Component;import java.util.ArrayList; import java.util.Collection; import java.util.List;/*** 组合对象组合对象里面包含其他的组合对象或者是叶子对象* 由于类型不同需要分开记录*/ public class Composite extends Component {/*** 用来存储组合对象中包含的子组件对象*/private ListComponent childComponents null;/*** 组合对象的名字*/private String name ;/*** 构造方法*/public Composite(String name) {this.name name;}public void addChild(Component child) {// 延迟初始化if (childComponents null) {childComponents new ArrayList();}childComponents.add(child);}/*** 输出组合对象自身的结构*/public void printStruct(String prestr) {// 先把自己输出去System.out.println(prestr this.name);// 如果还包含有子组件那么就输出这些子组件对象if (this.childComponents ! null) {prestr ;// 输出当前对象的子对象了for (Component c : childComponents) {// 递归输出每个子对象c.printStruct(prestr);}}} }去掉了之前区分组合对象和叶子对象的方法。 Client // 定义所有的组合对象Component root new Composite(服装);Component c1 new Composite(男装);Component c2 new Composite(女装);// 定义所有的叶子对象Component leaf1 new Leaf(衬衣);Component leaf2 new Leaf(夹克);Component leaf3 new Leaf(裙子);Component leaf4 new Leaf(套装);// 按照树的结构来组合 组合对象和叶子对象root.addChild(c1);root.addChild(c2);c1.addChild(leaf1);c1.addChild(leaf2);c2.addChild(leaf3);c2.addChild(leaf4);// 调用跟对象的输出功能来输出整棵树root.printStruct();组合模式优缺点 思考  本质统一叶子对象和组合对象一视同仁全部当成Component对象 何时选用
http://www.tj-hxxt.cn/news/225107.html

相关文章:

  • 大兴安岭做网站市场监督管理局是干什么的
  • 卖网站赚钱吗wordpress 头部空白
  • 招标网站免费常州外贸人才网
  • 网站 术语wordpress怎么开启下载收费功能
  • 公司网站建设的重要性网站开发 实战
  • 左侧导航网站替网站做任务怎么做的
  • 济南做网站哪好一条 wordpress
  • 网站建设设计制作包头什么是网站名称
  • 北京市住房城乡建设部网站首页建设银行国际互联网网站是什么
  • 网站域名绑定上海新闻
  • 网站的建设思路黑龙江公共资源交易网官网
  • 无锡网络公司无锡网站推广湛江关键词优化报价
  • 2在线做网站在线生成个人网站免费观看
  • 在意派建设好网站后我网站关键词太多
  • 网站的投资和建设项目企业做网站能赚钱么
  • 做果盘网站做游戏破解版的网站
  • 如何创建网站和域名成都私人做网站建设的公司
  • 适合服务行业做推广的网站微信商户平台
  • 国外的自建网站怎么做中企动力是国企性质吗
  • 合肥高端网站建设公司哪家好百色seo快速排名
  • 比较好的前端网站网站的外链接数
  • 合肥网站排名提升最好看免费观看高清视频了
  • 网站运营每天做的网站设计与网页配色实例精讲pdf
  • 蓝色大气网站源码企业宣传手册模板免费
  • 做金融怎么进基金公司网站即便你卖的是
  • 那个网站可以接做网页私活网站建设服务费计入会计科目
  • 福清市建设局监督站网站企业推广平台
  • 广东省建设合同备案网站电子产品网站建设
  • 北京营销型网站推广樱花12e56
  • 手机网站建设目标邦拓网站建设