Defensive Programming via Validating Decorators
Please read the original blog post by Yegor Bugayenko. He uses Java in the examples so I have tried to...
Dynamically extended helper module in presenter class
# models/movie.rb class Movie include ActiveModel::Model attr_accessor :id, :title, :genres, :date, :rating end # presenters/movies_presenter.rb require 'erb' class MoviesPresenter
Form Objects and Transactions (multiple models)
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...
Decorating ActiveRecord
It’s common to use the decorator/presenter pattern to wrap ActiveRecord objects and add view-specific logic. For example:
Chain of Responsibility Pattern
The chain of responsibility is most useful when related objects are all trying to handle the same request. Let's...
Command Pattern
This pattern a simple but deceptively powerful technique that decouples events — such as user interface interactions — from the concrete actions...
Primitive obsession
What is primitive obsession? Primitive Obsession is using primitive data types to represent domain ideas. For example, we use a...
Reusable Object-Oriented Systems
Simple Inheritance require 'json' module MovieFacts class Director def initialize(json) @raw_data = JSON.parse(json) end def name @raw_data.fetch('name...
Policy Objects
The Policy Objects design pattern is similar to Service Objects, but is responsible for read operations while Service Objects are...
Value Object
The main purpose of a value object is answer meaningful questions for our application. class Temperature include Comparable def initialize...
Whole Value (Value Object)
We’re writing software for managing a coffee shop. class CoffeeBatch attr_reader :bean_origin, :roast_level, :roast_date
Form Object from Railscasts
Models in a Rails application can easily become very complicated as more logic gets added to them. Fortunately there are...
Presenter from Railscasts
Let's say we have a user page with different textual and graphical information. Usually it means there will be...
Notification
Replacing exceptions with Notification in validations A common way to approach validation is to run series of checks on some...
Memento
The memento pattern is a software design pattern that provides the ability to restore an object to its previous state...