How do Adapters compare to the MVC architecture?ΒΆ

In Grok you have View and Model components. Applications written in them are also likely to generate additional code that needs to sit between your Views and your Models. Adapters are one solution for keeping this code out of your Models or Views and putting them into a place where they can easily be reused. Put as simply as possible, an Adapter takes the Interface of an existing component and adapts it to provide another Interface.

If you are used to other web frameworks that use a Model-View-Controller (MVC) architecture, such as Ruby on Rails, you may be thinking, “Isn’t the glue code between the Model and the View called a Controller?” Adapters differ from common MVC web architecture in that your Views can either access the Model directly, or extend the Model using one or more Adapters as intermediate actors. Adapters differ from Controllers in that they can adapt any type of component, and not just a Model component.

The Zope Component architecture approach page says, “The main idea in the Zope Component Architecture is the use of components, rather than multiple-inheritance for managing complexity”. One of the benefits of Adapters over multiple-inheritance is that you can extend the behavior of a Class without needing to modify the code for that Class. If you are acting upon a component provided by someone else, and that component has a well defined interface, then adaption is a much more robust way of extending the behaviour of that component than using meta programming techniques such as monkey patching.