Architecture Patterns Flashcards
Can you describe application without layers?
For example desktop application. Everything inside 1 file.
When you click button -> SQL starts doing something directly.
What 3 the most important layers do you know?
- presentation
- domain ( business logic)
- data source
How to check that your layers are independent from each other?
Business logic check:
- Replace interface ( for example from WEB to console) and ask if you need to duplicate domain code?
- Replace data source ( for example from DB to XML file) and ask if you need to change something inside the domain logic
What 3 pattern to handle domain layer do you know?
- Transaction Script ( Receive something from the view -> do some procedures -> return the result ) Example: Money transfer
- Domain Model ( You create many models -> every model has some methods ) Example: Internet Shop Cart
- Table module ( Organizes domain logic with one class per table in the database, something like singleton)
What is Active Record pattern?
An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data.
What is Table Data Gateway pattern?
An object that acts as a Gateway to a database table. One instance handles all the rows in the table. ( Something like update_all in rails)
What are the difference between Row Data Gateway and ActiveRecord?
It’s often hard to tell the difference between a Row Data Gateway and an Active Record.The crux of the matter is whether there’s any domain logic present; if there is, you have an Active Record. A Row Data Gateway should contain only database access logic and no domain logic.
What is Data Mapper pattern?
The Data Mapper is a layer of software that separates the in-memory objects from the database. With the Data Mapper Pattern, the in-memory objects have no idea there is a database, and the database schema is unaware of any objects that use it. This separation is the main purpose of a Data Mapper.
(Something like decorator that accept clear object and gives you active_record methods. Customer and CustomerMapper classes)
What is Unit of Work pattern?
The Unit of Work pattern is used to group one or more operations (usually database CRUD operations) into a single transaction or “unit of work” so that all operations either pass or fail as one unit. ( Something like our Unit on the project)
What is Identity Map pattern?
Ensures that each object gets loaded only once by keeping every loaded object in a map (hash/variable). Looks up objects using the map when referring to them. ( Looks like object that we create inside initialize which preload all required db records and then we work with this object through multiply classes)
What is Lazy Load pattern?
An object that doesn’t contain all of the data you need but knows how to get it.
For example ActiveRecord object doesn’t load all association by default, but can request them if needed.
What is Service Stub pattern?
Removes dependence upon problematic services during testing. ( the same as stub in rspec)
What is Identity Field pattern?
Saves a database ID field in an object to maintain identity between an in-memory object and a database row. ( The same as active record id)
What is Foreign Key Mapping pattern?
Maps an association between objects to a foreign key reference between tables. ( the same as association in rails)
What is Dependent Mapping pattern?
Has one class perform the database mapping for a child class. ( It’s like dependent destroy or strict foreign key. A separate class where changes to parent class requires to change and child association as well)
What is Association Table Mapping pattern?
Saves an association as a table with foreign keys to the tables that are linked by the association. ( When you have many to many associations and create ‘through’ table with foreign keys )