用通俗的话理解设计模式--Adapter pattern to Facade pattern

本文探讨了适配器模式和外观模式的核心概念及应用。适配器模式旨在将一个类的接口转换为客户期望的另一个接口,分为对象适配器和类适配器两种类型。而外观模式则创建了一个简单的接口,隐藏了复杂子系统的实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Adapter Pattern:

     the intent is converting the interface of a class into another interface the clients expect.

    it includes two main kinds. First is the Object Adapter, and the second is Class Adapter.

    Object Adapter pattern is using object composition.

    It's very simply if the adatpee and  adapter has unique counterpart property or method. 

    In my opionin, the adapter just straightforward pass through the field in the adaptee.

the Difference between Adapter pattern and Decorater pattern:

    Decorater pattern is to add responsiblity in the existing class(or interface?).

    Adapter pattern is converting the interface to another different interface expected by the client.

Facade Pattern:

     creat a class which has a simple and clean functionary for the client, and this class implement  is accomplished by a more complex subsystems(a lot of class).

     The principle of Least Knowledege should be applied  when FacadeClass invokes one method in the subsystem.

 

 My question is:

        1. if the fields in the adapter and the adaptee is incompatible, how to create an adapting interface for the client? As shown in <Head First>, throw unknown exception?

        2. the Facade pattern is much more like to create a new class and the methods in this class is totally decided by the Client. However, what seems weird is that the new classjust invoke some functionary in other classes?

                             

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值