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

做货代用的网站怎么写软文推广

做货代用的网站,怎么写软文推广,规划网站站点需要遵循哪些原则,梁平集团网站建设场景 设计模式-装饰者模式在Java中的使用示例: 设计模式-装饰者模式在Java中的使用示例_java装饰者模式例子-CSDN博客 上面装饰器的调用示例如下 AbstarctComputer computer;//要买1台电脑computer new BaseComputer();//加一个内存条computer new MemoryDecor…

场景

设计模式-装饰者模式在Java中的使用示例:

设计模式-装饰者模式在Java中的使用示例_java装饰者模式例子-CSDN博客

上面装饰器的调用示例如下

        AbstarctComputer computer;//要买1台电脑computer = new BaseComputer();//加一个内存条computer = new MemoryDecorator(computer);//加一个硬盘computer = new DiskDecorator(computer);//再加一个内存条computer = new MemoryDecorator(computer);System.out.println(computer.getMsg()+",总价:"+computer.getPrice());

下面记录一个它的变形,以软件设计师2016年下半年试题六为例

某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,

得到如图6-1所示的类图

注:

博客:
霸道流氓气质-CSDN博客

实现

1、新建发票正文类

public class Invoice {public void printInvoice(){System.out.println("This is the content of the invoice !");}
}

2、新建普通装饰器

public class Decorator extends Invoice{protected Invoice ticket;public Decorator(Invoice t){ticket = t;}public void printInvoice(){if(ticket !=null){ticket.printInvoice();}}
}

3、新建抬头装饰器

public class HeadDecorator extends Decorator{public HeadDecorator(Invoice t) {super(t);}public void printInvoice(){System.out.println("This is the header of the invoice!");super.printInvoice();}
}

4、新建脚注装饰器

public class FootDecorator extends Decorator{public FootDecorator(Invoice t) {super(t);}public void printInvoice(){super.printInvoice();System.out.println("This is the footnote of the invoice !");}
}

5、调用示例

        Invoice t = new Invoice();Invoice ticket;ticket = new HeadDecorator(new FootDecorator(t));ticket.printInvoice();System.out.println("----------------------------");ticket = new HeadDecorator(new FootDecorator(null));ticket.printInvoice();

以上调用输出结果

This is the header of the invoice!
This is the content of the invoice !
This is the footnote of the invoice !
----------------------------
This is the header of the invoice!
This is the footnote of the invoice !

6、分析

基础回顾

子类创建对象时,会先调用父类的构造方法,然后再调用子类自己的构造方法。
但是,如果子类没有显式地定义构造方法,会使用默认的无参构造方法。

这就是为什么有时候我们需要重写继承的构造方法的原因。
 
在继承中,子类可以通过super关键字调用父类的构造方法。如果子类没有使用super关键字调用父类的构造方法,

Java会自动调用父类的无参构造方法。如果父类没有提供无参构造方法,且子类没有显示地调用其他构造方法,会导致编译错误
 
在父类中只有 有参构造函数,没有无参构造函数,子类如果不写构造函数,系统默认创建一个无参构造函数,

子类这个无参的构造函数就会去调用父类的无参构造函数,时候就出错。

以上链式调用时

        ticket = new HeadDecorator(new FootDecorator(t));
        ticket.printInvoice();

不好理解,可以将其修改为如下便于理解

        Invoice t = new Invoice();t.printInvoice();FootDecorator footDecorator = new FootDecorator(t);footDecorator.printInvoice();Invoice ticket = new HeadDecorator(footDecorator);ticket.printInvoice();

实现过程分步解析

首先是FootDecorator footDecorator = new FootDecorator(t)

先调用FootDecorator的构造方法,将t(设定地址为Invoice@506)通过构造方法传参传递

并在FootDecorator的构造方法中调用super(t)将其传到父类Decorator的构造方法中进行

 protected Invoice ticket的属性的赋值。此时父类Decorator的ticker为Invoice@506

然后将上面新建的footDecorator(设定地址为FootDecorator@509)传递给HeadDecorator的构造方法

此时Invoice t为FootDecorator@509,在其构造方法中通过super(t)调用父类构造方法,并将其赋值给

父类Decorator的protected Invoice ticket,所以此时父类Decorator的ticket为FootDecorator@509

返回值为HeadDecorator的对象(设定为HeadDecorator@511)

然后调用HeadDecorator@511的printInvoice方法

在printInvoice方法中,先输出

This is the header of the invoice!

然后调用父类Decorator的printInvoice方法

此时父类Decorator的ticket为FootDecorator@509,不为空,所以会调用FootDecorator对象FootDecorator@509

的printInvoice方法,方法中会先调用其父类的printInvoice方法,FootDecorator@509父类对象的ticket为Invoice@506

Invoice@506调用printInvoice方法会输出

This is the content of the invoice !

然后FootDecorator@509的printInvoice方法继续输出

This is the footnote of the invoice !

http://www.tj-hxxt.cn/news/48688.html

相关文章:

  • 网站被搜索引擎收录今日新闻头条内容
  • 网站怎么做长尾关键词app拉新推广赚佣金
  • 怎么做劫持网站百度官网推广平台
  • 谷歌怎么把两个网站做反链互联网营销师证书怎么考多少钱
  • 做动态网站的用工具国际新闻最新消息2022
  • 网站开发者收入来源软文案例300字
  • 织梦网站如何做优化seo学堂
  • 将公司网站建设成厦门网络推广公司
  • 凡科精选app重庆搜索引擎seo
  • 网站建社石家庄信息流广告推广
  • 营销型网站建设都具有哪些优势关联词有哪些关系
  • 武汉网站开发软件程序员seo优化 搜 盈seo公司
  • 传奇网站如何建设百度官网网页版
  • vps配置iis网站百度关键词排名突然没了
  • 网站开发流程书籍百度浏览器极速版
  • 网站需要收集什么建站资源推广平台排名
  • 苏州seo推广优化seo怎么刷排名
  • 唐山建设集团网站如何进行品牌营销
  • 个人网站建设 免费微信朋友圈广告如何投放
  • 电脑系统做的好的网站好十大放黄不登录不收费
  • 北京医疗机构网站前置审批需要的材料有哪些互联网seo是什么
  • 做网站高手电商培训机构排名
  • 网站建设w亿码酷1流量订制软件推广方案经典范文
  • 学校网站怎么做的好处网络推广有哪些渠道
  • 国外创意包装设计欣赏郑州seo外包顾问热狗
  • 网站如何做线上推广灯塔seo
  • 真正学做网站要多久新站seo优化快速上排名
  • wordpress建视频网站可以吗苏州网站外包
  • 制作网页怎么插入图片上海专业的seo推广咨询电话
  • 合肥市有做网站的公司吗舆情报告范文