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

长春联通网站备案小广告怎么做

长春联通网站备案,小广告怎么做,汕头昨晚发现一例,画廊网站建设使用Golang实现开发中常用的【实例设计模式】 设计模式是解决常见问题的模板#xff0c;可以帮助我们提升思维能力#xff0c;编写更高效、可维护性更强的代码。 单例模式#xff1a; 描述#xff1a;确保一个类只有一个实例#xff0c;并提供一个全局访问点。 优点…使用Golang实现开发中常用的【实例设计模式】 设计模式是解决常见问题的模板可以帮助我们提升思维能力编写更高效、可维护性更强的代码。 单例模式 描述确保一个类只有一个实例并提供一个全局访问点。 优点节省资源避免重复创建对象。 缺点单例对象通常是全局可访问的容易引起耦合。 package singletonimport (sync )type Singleton struct {value string }var instance *Singleton var once sync.Oncefunc GetInstance() *Singleton {once.Do(func() {instance Singleton{}})return instance }func (s *Singleton) SetValue(value string) {s.value value }func (s *Singleton) GetValue() string {return s.value }工厂模式 描述提供一个创建对象的接口但由子类决定实例化哪一个类。 优点将对象的创建和使用分离提高代码的灵活性。 缺点增加了代码的复杂性。 package factorytype Product interface {Use() }type ConcreteProductA struct{}func (p *ConcreteProductA) Use() {println(Using ConcreteProductA) }type ConcreteProductB struct{}func (p *ConcreteProductB) Use() {println(Using ConcreteProductB) }type Factory interface {CreateProduct() Product }type ConcreteFactoryA struct{}func (f *ConcreteFactoryA) CreateProduct() Product {return ConcreteProductA{} }type ConcreteFactoryB struct{}func (f *ConcreteFactoryB) CreateProduct() Product {return ConcreteProductB{} }观察者模式 描述定义了对象之间的一对多依赖关系当一个对象的状态改变时所有依赖于它的对象都会得到通知。 优点实现了对象之间的松耦合。 缺点如果观察者数量过多通知过程可能会变得复杂。 package observertype Subject interface {RegisterObserver(observer Observer)RemoveObserver(observer Observer)NotifyObservers() }type Observer interface {Update(data string) }type ConcreteSubject struct {observers []Observerstate string }func (s *ConcreteSubject) RegisterObserver(observer Observer) {s.observers append(s.observers, observer) }func (s *ConcreteSubject) RemoveObserver(observer Observer) {for i, obs : range s.observers {if obs observer {s.observers append(s.observers[:i], s.observers[i1:]...)break}} }func (s *ConcreteSubject) NotifyObservers() {for _, observer : range s.observers {observer.Update(s.state)} }func (s *ConcreteSubject) SetState(state string) {s.state states.NotifyObservers() }type ConcreteObserver struct {name string }func (o *ConcreteObserver) Update(data string) {println(o.name, received:, data) }策略模式 描述定义一系列算法把它们一个个封装起来并且使它们可以互相替换。 优点算法的变化独立于使用算法的客户。 缺点增加了代码的复杂性。 package strategytype Strategy interface {Execute(data string) string }type Context struct {strategy Strategy }func (c *Context) SetStrategy(strategy Strategy) {c.strategy strategy }func (c *Context) ExecuteStrategy(data string) string {return c.strategy.Execute(data) }type ConcreteStrategyA struct{}func (s *ConcreteStrategyA) Execute(data string) string {return ConcreteStrategyA executed with data }type ConcreteStrategyB struct{}func (s *ConcreteStrategyB) Execute(data string) string {return ConcreteStrategyB executed with data }装饰者模式 描述动态地给一个对象添加一些额外的职责而不必修改对象结构。 优点增加了代码的灵活性和可扩展性。 缺点增加了代码的复杂性。 package decoratortype Component interface {Operation() string }type ConcreteComponent struct{}func (c *ConcreteComponent) Operation() string {return ConcreteComponent operation }type Decorator struct {component Component }func NewDecorator(component Component) *Decorator {return Decorator{component: component} }func (d *Decorator) Operation() string {return d.component.Operation() }type ConcreteDecoratorA struct {Decorator }func (d *ConcreteDecoratorA) Operation() string {return ConcreteDecoratorA added to d.Decorator.Operation() }type ConcreteDecoratorB struct {Decorator }func (d *ConcreteDecoratorB) Operation() string {return ConcreteDecoratorB added to d.Decorator.Operation() }代理模式 描述为其他对象提供一种代理以控制对这个对象的访问。 优点增加了安全性和灵活性。 缺点增加了代码的复杂性。 package proxytype Subject interface {Request() string }type RealSubject struct{}func (r *RealSubject) Request() string {return RealSubject handling request }type Proxy struct {realSubject *RealSubject }func NewProxy() *Proxy {return Proxy{realSubject: RealSubject{},} }func (p *Proxy) Request() string {// Pre-processingprintln(Proxy: Checking access prior to firing a real request.)// Delegate to the real subjectresult : p.realSubject.Request()// Post-processingprintln(Proxy: Logging the time of request.)return result }分别调用不同模式的对象实例 package mainimport (fmtsingletonfactoryobserverstrategydecoratorproxy )func main() {// 单例模式singleton.GetInstance().SetValue(Hello, Singleton!)fmt.Println(singleton.GetInstance().GetValue())// 工厂模式factoryA : factory.ConcreteFactoryA{}productA : factoryA.CreateProduct()productA.Use()factoryB : factory.ConcreteFactoryB{}productB : factoryB.CreateProduct()productB.Use()// 观察者模式subject : observer.ConcreteSubject{}observerA : observer.ConcreteObserver{name: ObserverA}observerB : observer.ConcreteObserver{name: ObserverB}subject.RegisterObserver(observerA)subject.RegisterObserver(observerB)subject.SetState(New State)// 策略模式context : strategy.Context{}strategyA : strategy.ConcreteStrategyA{}strategyB : strategy.ConcreteStrategyB{}context.SetStrategy(strategyA)fmt.Println(context.ExecuteStrategy(Data))context.SetStrategy(strategyB)fmt.Println(context.ExecuteStrategy(Data))// 装饰者模式component : decorator.ConcreteComponent{}decoratorA : decorator.ConcreteDecoratorA{Decorator: *decorator.NewDecorator(component)}decoratorB : decorator.ConcreteDecoratorB{Decorator: *decorator.NewDecorator(decoratorA)}fmt.Println(decoratorB.Operation())// 代理模式proxy : proxy.NewProxy()fmt.Println(proxy.Request()) }
http://www.hkea.cn/news/14403280/

相关文章:

  • 刚做的网站关键字能搜到么qq个人邮箱登录入口
  • 建立公司网站步骤wordpress轮播插件下载
  • 自己建立网站怎么建福田蒙派克4s店电话和地址
  • wordpress搬站换空间wordpress邮件发布
  • 免费网站空间 - 百度wordpress常用插件汇总 知更鸟
  • 区块链网站用vue.js做怎么样移动宽带怎么网上续费
  • 做企业网站制作郑佩佩 最新消息
  • 网课网站桂阳县网站建设公司哪家好
  • 旅游网站建设主要工作手机响应式网站开发模板之家
  • 网站建设服务器主板1150针河南企业网络推广方法
  • 小程序同步wordpress佛山百度seo代理
  • 网站建设人群定位ds2600ii色带
  • 在线做图的网站一级消防工程师考试科目和题型
  • 如何制作网站的步骤潮州住房与建设局网站
  • 口碑好的网站设计制作价格郑州优化网站公司
  • 十几万 建设网站mvc做门户网站
  • 做个网站需要多少钱vi设计风格有哪些
  • zen cart 网站google plus保定哪个公司做网站好
  • 东莞网站建设基本流程网站建设案例精粹
  • 什么行业愿意做网站php网站挂马
  • 农村电商网站建设做淘宝客网站好搭建吗
  • 无锡做网站哪个公司好找承包工程的平台
  • 株洲网站建设设计版面设计网站有哪些
  • 某企业网站建设方案论文在中国建的网站google可收录吗
  • 做网站卖仿品专业做网站建设
  • 网站开发流行昆明网站建设哪家公司好
  • 先做网站还是先备案月编程做网站
  • 营销型网站建设优化贵州城乡住房建设网站
  • 网站建设如何做wordpress 支付宝接入
  • 网站内容结构如何建立公司网站多少钱