Content deleted Content added
GraziePrego (talk | contribs) Adding local short description: "Concept in software engineering", overriding Wikidata description "design pattern for software that stores in-memory object data in relational databases, with interface functions for insert, update and delete, and properties corresponding to the columns in the underlying database table" |
|||
(12 intermediate revisions by 9 users not shown) | |||
Line 1:
{{Short description|Concept in software engineering}}
In [[software engineering]], the '''active record pattern''' is an [[Architectural pattern (computer science)|architectural pattern]]. It is found in software that stores in-memory object data in [[relational database]]s. It was named by [[Martin Fowler (software engineer)|Martin Fowler]] in his 2003 book ''Patterns of Enterprise Application Architecture''.<ref>[https://martinfowler.com/eaaCatalog/activeRecord.html P of EAA Catalog - Active Record]</ref><ref>{{cite book |last=Fowler |first=Martin |title=Patterns of enterprise application architecture |publisher=Addison-Wesley |year=2003 |isbn=978-0-321-12742-6 |url=https://books.google.com/books?id=FyWZt5DdvFkC&q=active+record&pg=PT187 }}</ref> The interface of an object conforming to this pattern would include functions such as Insert, Update, and Delete, plus properties that correspond more or less directly to the columns in the underlying database table.
Line 7 ⟶ 8:
== Implementations ==
Implementations of the concept can be found in various [[Software framework|framework]]s for many programming environments. For example, if there is a table <code>parts</code> in a database with columns <code>name</code> (string type) and <code>price</code> (number type), and the Active Record pattern is implemented in the class <code>Part</code>, the pseudo-code
{{sxhl|2=ruby|1=
}}
will create a new row in the <code>parts</code> table with the given values, and is roughly equivalent to the [[SQL]] command
Line 20 ⟶ 21:
Conversely, the class can be used to query the database:
{{sxhl|2=ruby|1=
b = Part.find_first("name", "gearbox")
}}
This will find a new <code>Part</code> object based on the first matching row from the <code>parts</code> table whose <code>name</code> column has the value "gearbox". The SQL command used might be similar to the following, depending on the SQL implementation details of the database:
Line 31 ⟶ 32:
== Criticism ==
===
Because the data and the database access methods are in the same file, those files end up being bigger.
=== Single responsibility principle and separation of concerns ===
Another critique of the active record pattern is that,
== See also ==
|