Shiro使用到的典型设计模式——Facade

Shiro使用到的典型设计模式Facade

1.Facade定义

首先,来看一段关于Facade模式的定义:Facade Pattern says that just “just provide a unified and simplified interface to a set of interfaces in a subsystem, therefore it hides the complexities of the subsystem from the client”.

翻译一下就是,门面模式(又称外观模式,我更喜欢门面模式的翻译)只是为子系统的一组接口提供了统一和简化的接口,因此它对客户端隐藏了子系统的复杂性。

In other words, Facade Pattern describes a higher-level interface that makes the sub-system easier to use.

换句话说,Facade Pattern描述了一个更高级别的接口,它使子系统更易于使用。

Practically, every Abstract Factory is a type of Facade.

实际上,每个抽象工厂都是一种门面。

2.Facade模式典型类图

以下是一个典型的Facade模式类图,Facade类对客户Client类隐藏了具体实现逻辑,同时,也提供了访问子系统类的接口。
​​​​​​请添加图片描述

3.Shiro的Facade模式类图

上一篇文章Shiro源码解析之认证代码走查中最后章节提供了一张类图,其实已经能够看出来逻辑,现在参照第2点的典型类图做一下简化如下:
在这里插入图片描述
SecurityManager就是Facade角色类,Subject的实现类DelegatingSubject中有一个SecurityManager类型的成员变量,而SecurityManager是继承自Authenticator接口和Authorizer接口,因此,也会继承接口的方法,所以,subject对象的所有方法都能够交给SecurityManager这个Facade类来处理,而不用去关心子类的具体细节(虚线框内,登录认证、授权的过程,对subject都是隐藏实现的)。

以上就是我个人关于Shiro典型的Facade模式应用的理解。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值