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

做网站的五要素wordpress媒体库 下载

做网站的五要素,wordpress媒体库 下载,seo点击排名工具,定机票最便宜网站建设使用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.w-s-a.com/news/128155/

相关文章:

  • 电子商务网站建设预算表网站建设卩金手指科杰
  • 广西响应式网站哪家好产品网络推广怎样做
  • 移动网可以上的网站是什么样子的淘宝优惠券网站开发
  • wordpress php设置伊宁seo网站建设
  • 兰陵住房建设局网站wordpress中文标题
  • 福州搜索优化网站个人网页网站制作模板
  • 网站开发分哪几个步骤使用wordpress开发一个页面跳转
  • 网站制作后还能更改么wordpress 近期文章 代码
  • 做一个小网站需要多少钱wordpress集成paypal
  • 加强网站建设管理 及时更新自己设计装修的app
  • 集团网站设计案例网页制作网站开发
  • 怎么优化网站的单个关键词排名惠州品牌网站建设
  • 上海跨境电商网站制作wordpress弃用react
  • phpcms网站模版下载电商网站建设属于研发费用吗
  • 动画毕业设计代做网站高校门户网站建设需要多少钱
  • 网站内链设置wordpress前台特别慢
  • 杭州模板网站建设系统江苏省建设考试网站准考证打印
  • 国家建设执业资格注册中心网站企业手机网站建设机构
  • 内容管理系统做网站怎么做英文版的网站
  • 浙江省专业网站制作网站建设网站设计及内容策划
  • 浙江门户网站建设公司做网站上哪买空间
  • 郑州网站怎么推广贵阳市网站建设
  • 规范网站建设福州外贸网站建设推广
  • 平台电商网站开发传媒公司排行
  • 在哪给人做网站怎么样制作一个网页
  • 网站更改文章标题广西新闻
  • 专业做网站路桥寺院网站建设方案
  • 网站维护与优化教程广州做网站的网络公司排名
  • 网站做贷款许可证网站改版方案模板
  • 装饰公司怎么做网站嘉兴网站制作推广