Naming convention for null objects in Rails?

For rails applications: is there a naming convention for assigning null objects that appear for model objects?

Example:

#app/models/blog.rb
class Blog < ActiveRecord::Base
end

#app/models/null_blog.rb
class NullBlog # Null Objects are POROs, correct?
  def title
    "No title"
  end
end

# so to implement it I can do this:
blogs = ids.map{|id| Blog.find_by(id: id) || NullBlog.new}
# which allows me to do this and it works, even if some of those ids did not find a blog
blogs.each{|blog| blog.title}

Is it NullBlogordinary?

Neither this article by Avdi Grimm nor Nothing is Something Sandy Mets presentation mentioned any null object naming convention.

+4
source share
1 answer

. , . , , ButBot, :

, , (, vs NullUser, CachedRequest RequestDecorator).

"" " ". , , - , . Object Thinking.

+4

Source: https://habr.com/ru/post/1611154/


All Articles