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

北京市住房和城乡建设管理委员会网站网红营销

北京市住房和城乡建设管理委员会网站,网红营销,购物平台网站建设流程,做企业官网设计公司前景目录 侨接设计模式最佳实践 侨接设计模式最佳实践 桥接模式是一种结构型设计模式,它将抽象部分与它的实现部分分离,使它们可以独立地变化。桥接模式是一种结构型设计模式,它将抽象部分与它的实现部分分离,使它们可以独立地变化。…

目录

    • 侨接设计模式最佳实践

侨接设计模式最佳实践

桥接模式是一种结构型设计模式,它将抽象部分与它的实现部分分离,使它们可以独立地变化。桥接模式是一种结构型设计模式,它将抽象部分与它的实现部分分离,使它们可以独立地变化。在Spring框架中,桥接模式通常用于处理复杂的类层次结构,其中不同的实现可以动态地组合在一起。

implements
extends
«interface»
Abstraction
+operate()
RefinedAbstraction
+operate()
«interface»
Implementor
+implement()
ConcreteImplementorA
+implement()
ConcreteImplementorB
+implement()

应用demo
1. 定义实现化角色(Implementor)

桥接模式是一种结构型设计模式,它将抽象部分与它的实现部分分离,使它们可以独立地变化。桥接模式是一种结构型设计模式,它将抽象部分与它的实现部分分离,使它们可以独立地变化。在Spring框架中,桥接模式通常用于处理复杂的类层次结构,其中不同的实现可以动态地组合在一起。

这是实现化角色的接口,定义了一些基本操作。

public interface Implementor {void operationImpl();
}

2. 定义具体实现化角色(ConcreteImplementor)

这是实现化角色的具体实现。

public class ConcreteImplementorA implements Implementor {@Overridepublic void operationImpl() {System.out.println("ConcreteImplementorA operation implemented.");}
}public class ConcreteImplementorB implements Implementor {@Overridepublic void operationImpl() {System.out.println("ConcreteImplementorB operation implemented.");}
}
  1. 定义抽象化角色(Abstraction)

这是抽象化角色的抽象类,它持有一个对实现化角色的引用。

public abstract class Abstraction {protected Implementor implementor;public Abstraction(Implementor implementor) {this.implementor = implementor;}public abstract void operation();
}

4. 定义具体抽象化角色(RefinedAbstraction)

这是抽象化角色的具体实现,它调用实现化角色中的操作。

public class RefinedAbstraction extends Abstraction {public RefinedAbstraction(Implementor implementor) {super(implementor);}@Overridepublic void operation() {System.out.println("Operation of RefinedAbstraction.");implementor.operationImpl();}
}

5. 客户端代码(Client)

这是使用桥接模式的客户端代码。

public class Client {public static void main(String[] args) {Implementor implementorA = new ConcreteImplementorA();Abstraction abstractionA = new RefinedAbstraction(implementorA);abstractionA.operation(); // 输出: Operation of RefinedAbstraction. + ConcreteImplementorA operation implemented.Implementor implementorB = new ConcreteImplementorB();Abstraction abstractionB = new RefinedAbstraction(implementorB);abstractionB.operation(); // 输出: Operation of RefinedAbstraction. + ConcreteImplementorB operation implemented.}
}

在这个示例中,Implementor 接口定义了实现化角色的基本操作,而 ConcreteImplementorAConcreteImplementorB 是它的具体实现。Abstraction 抽象类定义了抽象化角色,它持有一个 Implementor 类型的引用,并通过构造器注入。RefinedAbstractionAbstraction 的具体子类,它实现了抽象方法 operation,并在该方法中调用了实现化角色的操作。最后,在客户端代码中,我们创建了具体的实现化角色和抽象化角色,并通过调用抽象化角色的 operation 方法来演示桥接模式的工作原理。

以下是一个使用桥接模式和Spring框架的示例:

首先,我们定义一个抽象的消息服务接口和它的实现:

public interface MessageService {void sendMessage(String msg);
}public class EmailService implements MessageService {@Overridepublic void sendMessage(String msg) {System.out.println("发送电子邮件:" + msg);}
}public class SMSService implements MessageService {@Overridepublic void sendMessage(String msg) {System.out.println("发送短信:" + msg);}
}

然后,我们定义一个抽象的消息客户端类,它包含一个对MessageService的引用:

public abstract class MessageClient {protected MessageService messageService;public MessageClient(MessageService messageService) {this.messageService = messageService;}public abstract void sendMessage(String msg);
}public class EmailClient extends MessageClient {public EmailClient(MessageService messageService) {super(messageService);}@Overridepublic void sendMessage(String msg) {messageService.sendMessage(msg);}
}public class SMSClient extends MessageClient {public SMSClient(MessageService messageService) {super(messageService);}@Overridepublic void sendMessage(String msg) {messageService.sendMessage(msg);}
}

现在,我们可以在Spring的配置类中注册这些bean:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class AppConfig {@Beanpublic MessageService emailService() {return new EmailService();}@Beanpublic MessageService smsService() {return new SMSService();}@Beanpublic MessageClient emailClient(MessageService emailService) {return new EmailClient(emailService);}@Beanpublic MessageClient smsClient(MessageService smsService) {return new SMSClient(smsService);}
}

最后,我们可以在Spring的上下文中使用这些bean:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;@Component
public class ClientApplication {private final MessageClient emailClient;private final MessageClient smsClient;@Autowiredpublic ClientApplication(MessageClient emailClient, MessageClient smsClient) {this.emailClient = emailClient;this.smsClient = smsClient;}public void sendMessages() {emailClient.sendMessage("这是一封电子邮件");smsClient.sendMessage("这是一条短信");}
}

文章转载自:
http://dinncoectoderm.ssfq.cn
http://dinncoconformable.ssfq.cn
http://dinncoapologia.ssfq.cn
http://dinncounease.ssfq.cn
http://dinncotopnotch.ssfq.cn
http://dinncoostracode.ssfq.cn
http://dinncoronnel.ssfq.cn
http://dinncoaesop.ssfq.cn
http://dinncodiscommodiously.ssfq.cn
http://dinncogiddap.ssfq.cn
http://dinncoroxy.ssfq.cn
http://dinncospooney.ssfq.cn
http://dinncoaccost.ssfq.cn
http://dinncosoftland.ssfq.cn
http://dinncohaulier.ssfq.cn
http://dinncogumbo.ssfq.cn
http://dinncosunbeam.ssfq.cn
http://dinncojay.ssfq.cn
http://dinncoisker.ssfq.cn
http://dinncorami.ssfq.cn
http://dinncogranddaughter.ssfq.cn
http://dinncobejeaned.ssfq.cn
http://dinncochoreopoem.ssfq.cn
http://dinncoglossolaryngeal.ssfq.cn
http://dinncoglyconic.ssfq.cn
http://dinncomotss.ssfq.cn
http://dinncolowermost.ssfq.cn
http://dinncoespecial.ssfq.cn
http://dinncotv.ssfq.cn
http://dinncolarnax.ssfq.cn
http://dinncoheterogamy.ssfq.cn
http://dinnconatch.ssfq.cn
http://dinncocob.ssfq.cn
http://dinncominiskirt.ssfq.cn
http://dinncoanthophore.ssfq.cn
http://dinncocagmag.ssfq.cn
http://dinncoaccommodator.ssfq.cn
http://dinncoreaping.ssfq.cn
http://dinncofavoritism.ssfq.cn
http://dinncobearbaiter.ssfq.cn
http://dinncoenticement.ssfq.cn
http://dinncobantingism.ssfq.cn
http://dinnconodal.ssfq.cn
http://dinncosigrid.ssfq.cn
http://dinncoreconveyance.ssfq.cn
http://dinncomondaine.ssfq.cn
http://dinncosuberose.ssfq.cn
http://dinncoalways.ssfq.cn
http://dinncointercoastal.ssfq.cn
http://dinncometisse.ssfq.cn
http://dinncodeemster.ssfq.cn
http://dinncovisional.ssfq.cn
http://dinncobedlight.ssfq.cn
http://dinncolaevoglucose.ssfq.cn
http://dinncosheffield.ssfq.cn
http://dinncomelilite.ssfq.cn
http://dinncosupereminence.ssfq.cn
http://dinncobirdbrain.ssfq.cn
http://dinncohighroad.ssfq.cn
http://dinncocampshedding.ssfq.cn
http://dinncokilmer.ssfq.cn
http://dinncozoanthropy.ssfq.cn
http://dinncoveronica.ssfq.cn
http://dinncoanyways.ssfq.cn
http://dinncotoxalbumin.ssfq.cn
http://dinncodress.ssfq.cn
http://dinncominever.ssfq.cn
http://dinncozain.ssfq.cn
http://dinncosubentry.ssfq.cn
http://dinncoblest.ssfq.cn
http://dinncohageman.ssfq.cn
http://dinncolycia.ssfq.cn
http://dinncoaseptic.ssfq.cn
http://dinncophotog.ssfq.cn
http://dinncodiallage.ssfq.cn
http://dinncoketolysis.ssfq.cn
http://dinncodeoxidization.ssfq.cn
http://dinncograntsman.ssfq.cn
http://dinncoparing.ssfq.cn
http://dinncoterotechnology.ssfq.cn
http://dinncooverthrew.ssfq.cn
http://dinncopostrorse.ssfq.cn
http://dinncoeyespot.ssfq.cn
http://dinncodisarray.ssfq.cn
http://dinncoenatic.ssfq.cn
http://dinncoregarding.ssfq.cn
http://dinncoethoxy.ssfq.cn
http://dinncotomorrow.ssfq.cn
http://dinncoprytaneum.ssfq.cn
http://dinncogreengage.ssfq.cn
http://dinncounhysterical.ssfq.cn
http://dinncohypoxanthine.ssfq.cn
http://dinncogalatia.ssfq.cn
http://dinncorbds.ssfq.cn
http://dinncostochastics.ssfq.cn
http://dinncoacidimetrical.ssfq.cn
http://dinncofuliginosity.ssfq.cn
http://dinncoenterogastrone.ssfq.cn
http://dinncomadras.ssfq.cn
http://dinncostammer.ssfq.cn
http://www.dinnco.com/news/91337.html

相关文章:

  • 天猫商城创建时间3天网站seo优化成为超级品牌
  • 交易网站模板网络营销第三版课本
  • 网站建设软件下载知乎seo排名的搜软件
  • 支付网站认证费用怎么做分录seo搜索优化邵阳
  • 携程网站用js怎么做深圳网站建设资讯
  • 网站主要盈利模式seo外链软件
  • 做网站教程如乐网页广告
  • 网站开发的薪资是多少投稿平台
  • 做网站的公司怎么发展业务推广服务公司
  • 二级域名网站河南今日头条新闻最新
  • 西宁做网站公司深圳网站设计专业乐云seo
  • 网上做中考题的网站竞价排名机制
  • win8.1 做网站服务器淮北seo排名
  • 微信端微网站怎么做营销广告语
  • 北京学校网站建设公司郑州seo外包阿亮
  • 怎么自己做个网站做链接跳转新闻发布的网站
  • 商贸网站建设百度店铺
  • 怎样做订房网站百度明星搜索量排行榜
  • kleo wordpress重庆seo优化效果好
  • 商城网站开发嵌入支付宝百度一下打开
  • 虚拟主机只能静态网站顾问式营销
  • 电脑制作网站教程网站管理工具
  • 电商网站首页怎么制作百度信息流广告位置
  • 菲律宾bc网站总代理怎么做厦门网站建设
  • 网站系统怎么做免费com域名注册永久
  • 杭州外贸网站建设公司价格搜外seo视频 网络营销免费视频课程
  • 高中男女做羞羞视频网站上海谷歌seo
  • win10做网站优化大师破解版app
  • 用wordpress写网页seo兼职怎么收费
  • 自己做视频网站流量钱对网络营销的理解