Do ORM packages implement the Facade or Adapter pattern?

1.2k Views Asked by At

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

There are 1 best solutions below

0
On BEST ANSWER

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.