根据我的理解,适配器模式基本上是在另一个类上创建一个包装器,以便现有代码可以使用您正在包装的类。外观用于更改整个子系统(因此,如果您正在处理需要 5 个步骤的复杂绘图 api,您可以将它们合并为仅 1 个方法,例如)。那么我的问题是 ORM 使用哪种模式,还是两者都使用?
它们为许多不同的子系统提供了一个接口,但我仍然不确定,尽管我倾向于外观模式。
From my understanding the Adapter pattern is basically creating a wrapper on another class so that the class you are wrapping can be used by existing code. A facade is for changing an entire subsystem (so if you are dealing with a complicated drawing api that requires 5 steps you might consolidate them into just 1 method, as an example). My question then is which pattern do ORM's use, or is it both?
They provide a single interface into many different subsystems but I'm still not sure, though I'm leaning towards the facade pattern.
发布评论
评论(1)
对于我所了解的ORM框架来说,Adapter似乎并不是一个至关重要的模式。可以使用外观,例如在 Hibernate/JPA 中,其中有一个 Session/EntityManager 接口负责几乎所有事情,可能在幕后调用许多不同的子系统接口。
然而,还有很多其他模式在发挥作用。 工厂 模式经常使用,几乎不用说:-)另一个突出的模式(至少在 Hibernate 中)是 代理,这是延迟获取的基础。此外:对象池(用于数据库连接)、解释器(用于查询)...该列表可以继续。
For the ORM frameworks I know, Adapter does not seem to be a crucial pattern. Facade may be used, e.g. in Hibernate/JPA where there is a single Session/EntityManager interface responsible for almost everything, probably calling a lot of distinct subsystem interfaces behind the curtain.
However, there is a lot of other patterns in play. That the Factory patterns are used often is almost needless to say :-) Another prominent one (in Hibernate at least) is Proxy, which is fundamental in lazy fetching. Furthermore: Object Pool (for the DB connections), Interpreter (for queries)... the list could be continued.