Please read the original blog post by Yegor Bugayenko. He uses Java in the examples so I have tried to...
Let's say we have two associated models: # app/models/user.rb class User < ApplicationRecord has_one :location end # app/models/location.rb class Location < ApplicationRecord...
It’s common to use the decorator/presenter pattern to wrap ActiveRecord objects and add view-specific logic. For example:
The chain of responsibility is most useful when related objects are all trying to handle the same request. Let's...
This pattern a simple but deceptively powerful technique that decouples events — such as user interface interactions — from the concrete actions...
What is primitive obsession? Primitive Obsession is using primitive data types to represent domain ideas. For example, we use a...
Simple Inheritance require 'json' module MovieFacts class Director def initialize(json) @raw_data = JSON.parse(json) end def name @raw_data.fetch('name...
The Policy Objects design pattern is similar to Service Objects, but is responsible for read operations while Service Objects are...
The main purpose of a value object is answer meaningful questions for our application. class Temperature include Comparable def initialize...
Models in a Rails application can easily become very complicated as more logic gets added to them. Fortunately there are...
Let's say we have a user page with different textual and graphical information. Usually it means there will be...
Replacing exceptions with Notification in validations A common way to approach validation is to run series of checks on some...
The memento pattern is a software design pattern that provides the ability to restore an object to its previous state...