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

网站开发成本会计分录seo sem

网站开发成本会计分录,seo sem,如何注册一个网站域名,在线设计平台行业的发展趋势策略模式定义 比如对象的某个行为,在不同场景有不同实现方式,可以将这些行为的具体实现定义为一组策略,每个实现类实现种策略,在不同场景使用不同的实现,并且可以自由切换策略。 策略模式结构 策略模式需要一个策略…

策略模式定义

比如对象的某个行为,在不同场景有不同实现方式,可以将这些行为的具体实现定义为一组策略,每个实现类实现种策略,在不同场景使用不同的实现,并且可以自由切换策略。

策略模式结构

策略模式需要一个策略接口,不同的策略实现不同的实现类,在具体业务环境中仅持有该策略接口,根据不同的场景使用不同的实现类即可。
在这里插入图片描述

面向接口编程,而不是面向实现。

优点

1、干掉繁琐的 if、switch 判断逻辑;

2、代码优雅、可复用、可读性好;

3、符合开闭原则(对修改关闭, 对扩展开放),扩展性好、便于维护;

缺点

1、策略如果很多的话,会造成策略类膨胀;

2、使用者必须清楚所有的策略类及其用途;

策略模式代码示例

  • 基础登录接口
//基础登录接口
public interface BaseLoginService {void login(BaseLoginContext context);
}
  • 策略上下文实现
@Data
public class BaseLoginContext {private String userName;private String password;private BaseLoginService baseLoginService;public BaseLoginContext(String userName, String password, BaseLoginService baseLoginService) {this.userName = userName;this.password = password;this.baseLoginService = baseLoginService;}public void login(){baseLoginService.login(this);}
}
  • 定义具体的策略实现类
  1. 实现类1
public class SimpleLoginServiceImpl implements BaseLoginService {@Overridepublic void login(BaseLoginContext context) {System.out.println("简单登录,当前登录的人:" + context.getUserName() + ",密码:" + context.getPassword());}
}
  1. 实现类2
public class HardLoginServiceImpl implements BaseLoginService {@Overridepublic void login(BaseLoginContext context) {System.out.println("复杂登录,当前登录的人:" + context.getUserName() + ",密码:" + context.getPassword());}
}
  • 调用
public static void main(String[] args) {BaseLoginService simple = new SimpleLoginServiceImpl();BaseLoginContext simpleContext = new BaseLoginContext("simple","simple",simple);simpleContext.login();BaseLoginService hard = new HardLoginServiceImpl();BaseLoginContext hardContext = new BaseLoginContext("hard","hard",hard);hardContext.login();}
  • 结果
    在这里插入图片描述

扩展策略

方式1

在策略的算法实现上添加自己需要的数据的方式

public class CommonLoginServiceImpl implements BaseLoginService {private String userId;public CommonLoginServiceImpl(String userId) {this.userId = userId;}public String getUserId() {return userId;}@Overridepublic void login(BaseLoginContext context) {System.out.println("复杂登录,当前登录的人:" + context.getUserName() + ",账号:" + getUserId() + ",密码:" + context.getPassword());}
}
  • 调用
public static void main(String[] args) {BaseLoginService simple = new SimpleLoginServiceImpl();BaseLoginContext simpleContext = new BaseLoginContext("simple","simple",simple);simpleContext.login();BaseLoginService hard = new HardLoginServiceImpl();BaseLoginContext hardContext = new BaseLoginContext("hard","hard",hard);hardContext.login();BaseLoginService common = new CommonLoginServiceImpl("001");BaseLoginContext commonContext = new BaseLoginContext("common","common",common);commonContext.login();}
  • 结果
    在这里插入图片描述

方式2

扩展上下文的方式

public class NewLoginContext extends BaseLoginContext{private String userId;public String getUserId() {return userId;}public void setUserId(String userId) {this.userId = userId;}public NewLoginContext(String userName, String password, String userId, BaseLoginService baseLoginService) {super(userName, password, baseLoginService);this.userId = userId;}
}
  • 实现类
public class CommonLoginServiceImpl implements BaseLoginService {private String userId;public CommonLoginServiceImpl(String userId) {this.userId = userId;}public String getUserId() {return userId;}@Overridepublic void login(BaseLoginContext context) {NewLoginContext newLoginContext = (NewLoginContext)context;
//        System.out.println("common1登录,当前登录的人:" + context.getUserName() + ",账号:" + getUserId() + ",密码:" + context.getPassword());System.out.println("common2登录,当前登录的人:" + context.getUserName() + ",账号:" + newLoginContext.getUserId() + ",密码:" + context.getPassword());}
}
  • 调用
public static void main(String[] args) {BaseLoginService simple = new SimpleLoginServiceImpl();BaseLoginContext simpleContext = new BaseLoginContext("simple","simple",simple);simpleContext.login();BaseLoginService hard = new HardLoginServiceImpl();BaseLoginContext hardContext = new BaseLoginContext("hard","hard",hard);hardContext.login();//        BaseLoginService common1 = new CommonLoginServiceImpl("001");
//        BaseLoginContext commonContext1 = new BaseLoginContext("common","common",common1);
//        commonContext1.login();BaseLoginService common2 = new CommonLoginServiceImpl("001");NewLoginContext commonContext2 = new NewLoginContext("common","common","002",common2);commonContext2.login();}
  • 结果
    在这里插入图片描述
http://www.wangmingla.cn/news/106170.html

相关文章:

  • react用于做PC网站优化设计六年级上册语文答案
  • 快速搭建网站的工具有哪些专业关键词排名优化软件
  • ueditor解析wordpress四川seo优化
  • wordpress迁移上海seo网站推广
  • 扬州企业网站建设2023最新15件重大新闻
  • 闸北区网站建设二级网站怎么做
  • 网站维护页面怎么做的网络推广软件免费
  • 广告设计师证怎么考深圳搜索引擎优化推广便宜
  • 网站为什么要续费app推广文案
  • 预付网站建设费用会计分录一键搭建网站
  • 天津网站seo策划游戏推广员拉人技巧
  • js获取网站html百度霸屏全网推广
  • 网站建设08优化排名
  • 风机网站怎么做seo扣费系统
  • 全网网站建设维护小红书推广费用一般多少
  • jsp做网站图片怎么存储廊坊关键词排名首页
  • dw做网站弊端高州网站seo
  • 湖南定制响应式网站有哪些上海网站排名优化怎么做
  • 积分交易网站开发市场策划方案
  • 大连网站制作每日财经最新消息
  • 网站规划建设方案模板软文发布平台
  • 国际新闻最新消息今天新闻大事件 中方seo排名优化软件免费
  • 平台公司和国企的区别seo公司
  • 室内设计网站哪里可以看南宁百度关键词推广
  • goland 网站开发站长素材网站官网
  • 专业网站建设哪里好自助建站系统开发
  • 小说网站怎么做权重扬州网络推广公司
  • 电子网站搜索引擎怎么做河北seo人员
  • 有偿做设计的网站今日广州新闻最新消息
  • 调用其他网站文章列表seo综合查询怎么用