首页 \ 问答 \ Android适配器是适配器设计模式的一个例子吗?(Are android adapters an example of Adapter Design pattern?)

Android适配器是适配器设计模式的一个例子吗?(Are android adapters an example of Adapter Design pattern?)

Android适配器是否使用适配器设计模式? GoF设计模式书将适配器设计模式描述为

适配器模式将类的接口转换为客户期望的另一个接口。 适配器允许类一起工作,否则由于不兼容的接口。

有一个目标接口,适配器实现并且客户端使用(期望),并且有一个适配器,适配器委托客户端发出的所有请求。

我知道它的理论和现实世界模式适配器接口看起来并不完全一样,但我仍然无法弄清楚android适配器适应什么(目标接口是什么)以及实际请求的适配器。

我检查了这个这个这个 。 但是他们都没有解释清楚Android适配器是如何适配器设计模式的。 事实上, 第一第二个答案有些矛盾。

有人可以解释一下吗?


Do Android adapters use Adapter Design pattern? The GoF design patterns book describes Adapter Design Pattern as

The Adapter Pattern converts the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.

There's a target interface which the adapter implements and the client uses(expects) and there is an adaptee to which the adapter delegates all the requests made by client.

I understand that its theory and real world pattern adapter interfaces don't exactly look like it, but still I can't figure out what the android adapters adapt(what target interface) and to which adaptee are the requests actually made to.

I have checked this, this and this. But none of them explain clearly how is the android adapter the adapter design pattern. The 1st and 2nd answers, in fact, are somewhat conflicting.

Can anyone please explain this?


原文:https://stackoverflow.com/questions/41626980
更新时间:2023-08-01 09:08

最满意答案

Python字符串文字使用反斜杠作为转义字符。 字符串文字"\b"将包含退格字符(ASCII 0x8),就像"\n"将包含换行符一样。 它不会包含“反斜杠b”,正如你需要正则表达式工作一样。

要获得“反斜杠b”,您需要在字符串文字中转义反斜杠,或者分别使用原始字符串"\\b"r"\b"

regex = re.compile(old_name + r"\b", re.IGNORECASE)

通常,原始字符串用于Python中的正则表达式,因此不需要每个反斜杠加倍。

阅读https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals


注意: "\s"作用是因为 - 与"\b""\n"相反 - 它在Python字符串文字中没有特殊含义,所以它实际上成为正则表达式的“反斜杠s”。


Python string literals use the backslash as an escape character. The string literal "\b" will contain the backspace character (ASCII 0x8), just like "\n" will contain a newline. It will not contain "backslash b", as you would need for the regex to work.

To get "backslash b" you need to escape the backslash in the string literal, or use a raw string, which is "\\b" or r"\b", respectively.

regex = re.compile(old_name + r"\b", re.IGNORECASE)

Commonly, raw strings are used for regex in Python, so you don't need to double every backslash.

Read https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals


Side note: "\s" works because - in contrast to "\b" or "\n" - it means nothing special in a Python string literal, so it actually becomes "backslash s" for the regex.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。