Defensive Programming via Validating Decorators

Posted About 5 years ago by Alexander M.
yegor256.com

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

Posted Almost 7 years ago by Alexander M.

# 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)

Posted Almost 7 years ago by Alexander M.

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

Posted Almost 7 years ago by Alexander M.

It’s common to use the decorator/presenter pattern to wrap ActiveRecord objects and add view-specific logic. For example:

Chain of Responsibility Pattern

Posted About 7 years ago by Alexander M.

The chain of responsibility is most useful when related objects are all trying to handle the same request. Let's...

Command Pattern

Posted About 7 years ago by Alexander M.

This pattern a simple but deceptively powerful technique that decouples events — such as user interface interactions — from the concrete actions...

Primitive obsession

Posted About 7 years ago by Alexander M.

What is primitive obsession? Primitive Obsession is using primitive data types to represent domain ideas. For example, we use a...

Reusable Object-Oriented Systems

Posted Over 7 years ago by Alexander M.

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

Posted Over 7 years ago by Alexander M.

The Policy Objects design pattern is similar to Service Objects, but is responsible for read operations while Service Objects are...

Value Object

Posted Over 7 years ago by Alexander M.

The main purpose of a value object is answer meaningful questions for our application. class Temperature include Comparable def initialize...

Whole Value (Value Object)

Posted Over 7 years ago by Alexander M.

We’re writing software for managing a coffee shop. class CoffeeBatch attr_reader :bean_origin, :roast_level, :roast_date

Form Object from Railscasts

Posted Over 7 years ago by Alexander M.
railscasts.com

Models in a Rails application can easily become very complicated as more logic gets added to them. Fortunately there are...

Presenter from Railscasts

Posted Almost 8 years ago by Alexander M.

Let's say we have a user page with different textual and graphical information. Usually it means there will be...

Notification

Posted Almost 8 years ago by Alexander M.
martinfowler.com

Replacing exceptions with Notification in validations A common way to approach validation is to run series of checks on some...

Memento

Posted Almost 8 years ago by Alexander M.

The memento pattern is a software design pattern that provides the ability to restore an object to its previous state...