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
最满意答案
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"
orr"\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.
相关问答
更多-
看起来这是你的SQL语句: cursor.execute("INSERT INTO %s (description, url) VALUES (%s, %s);", (table_name.encode("utf-8"), key.encode("utf-8"), data[key].encode("utf-8"))) IIRC, 表的名称无法参数化 (因为它被不恰当地引用)。 你需要以其他方式将其注入到字符串中(最好是安全地 - 通过检查所请求的表名是否与列入白名单的表名相匹配)...例如: _TABL ...
-
使用Regex从包含SQL查询的文件中提取表名(Using Regex to extract table names from a file containing SQL queries)[2024-01-22]
这取决于您的文件的结构。 试着用这个: (?<=from|join)(\s+\w+\b) 如果您不将文件拆分为数组,或者使用单行字符串成员分割文件,也可以打开选项Multiline。 还尝试打开IgnorCase选项。 It depends on structure of your file. Try to use this: (?<=from|join)(\s+\w+\b) Also turn on options Multiline if your not split your file in ar ... -
您可以修改SQL,以便提取类似于某个描述的名称,然后从table2中输出匹配名称的值。 select name, value1, value2, value3, value4 from table2 where name in ( select name from table1 where description like ? ) You could amend your SQL so that you pull out the names that are like a cert ...
-
使用以前链接的副本,我已经修改它以指定从哪里开始搜索。 我不知道这是不是你想要的: string ReplaceFirst(string text, string search, string replace, string from) { int posFrom= text.ToLower().IndexOf(from.ToLower()); if (posFrom < 0) { return text; } int pos = tex ...
-
Python字符串文字使用反斜杠作为转义字符。 字符串文字"\b"将包含退格字符(ASCII 0x8),就像"\n"将包含换行符一样。 它不会包含“反斜杠b”,正如你需要正则表达式工作一样。 要获得“反斜杠b”,您需要在字符串文字中转义反斜杠,或者分别使用原始字符串"\\b"或r"\b" 。 regex = re.compile(old_name + r"\b", re.IGNORECASE) 通常,原始字符串用于Python中的正则表达式,因此不需要每个反斜杠加倍。 阅读https://docs.pyt ...
-
我会这样做: try { Pattern regex = Pattern.compile("(?:/\\*[^;]*?\\*/)|(?:--[^;]*?$)", Pattern.DOTALL | Pattern.MULTILINE); Matcher regexMatcher = regex.matcher(subjectString); while (regexMatcher.find()) { // matched text: regexMatcher.g ...
-
使用preg_match从create table语句中获取SQL表名(Get SQL table names from create table statements using preg_match)[2023-01-13]
所有你需要做的就是捕捉一个表名,它是用()完成的: preg_match('/create\s+table\s+\`?(\w+)`/i', $sql, $tables); var_dump($tables[1]) All you need to do is to catch a table name, it is done with (): preg_match('/create\s+table\s+\`?(\w+)`/i', $sql, $tables); var_dump($tables[1]) -
真的,这不是一件容易的事。 您可以使用词法分析器(在此示例中使用ply )并定义多个规则以从字符串中获取多个标记。 以下代码为SQL字符串的不同部分定义了这些规则,并将它们重新组合在一起,因为输入字符串中可能存在别名。 因此,您将获得一个字典( result ),其中包含不同的表名作为键。 import ply.lex as lex, re tokens = ( "TABLE", "JOIN", "COLUMN", "TRASH" ) tables = {"tables" ...
-
简单的正则表达式替换不能实现这一点。 您将无法区分作为表的大写单词,字符串文字或被注释: update TABLE set x='NOT_A_TABLE' where y='NOT TABLES EITHER' -- AND NO TABLES HERE AS WELL 编辑 您似乎认为确定单词是否在字符串文字内是很容易的,然后考虑这样的SQL: -- a quote: ' update TABLE set x=42 where y=666 -- another quote: ' 要么 update ...
-
您链接的示例代码包含对runTests的调用。 这是一个很好的工具,可以尝试不同的测试字符串,并为解析器编写单元测试。 在runTests调用中插入查询字符串时,我们得到以下输出: select z.a, b from test_table left join test2_table where 1=1 and b in (select bb from foo) ['SELECT', [['z.a'], ['b']], 'FROM', ['test_table', ['LEFT', 'JOIN'], 'te ...