Implementations of the concept can be found in various frameworks for many programming environments. For example, if there is a table parts in a database with columns name (string type) and price (number type), and the Active Record pattern is implemented in the class Part, the pseudo-code
will create a new row in the parts table with the given values, and is roughly equivalent to the SQL command
Conversely, the class can be used to query the database:
This will find a new Part object based on the first matching row from the parts table whose name column has the value "gearbox". The SQL command used might be similar to the following, depending on the SQL implementation details of the database:
Because the data and the database access methods are in the same file, those files end up being bigger.
Another critique of the active record pattern is that, due to the strong coupling of database interaction and application logic, an active record object does not follow the single responsibility principle and separation of concerns. This is opposed to multitier architecture, which properly addresses these practices. Because of this, the active record pattern is best and most often employed in simple applications that are all forms-over-data with CRUD functionality, or only as one part of an architecture. Typically that part is data access and why several ORMs implement the active record pattern.
P of EAA Catalog - Active Record https://martinfowler.com/eaaCatalog/activeRecord.html ↩
Fowler, Martin (2003). Patterns of enterprise application architecture. Addison-Wesley. ISBN 978-0-321-12742-6. 978-0-321-12742-6 ↩