Rails アプリケーションの場合: モデル オブジェクトにマップされる null オブジェクトに名前を付けるための命名規則はありますか?
例:
#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}
NullBlog
従来型ですか?
Avdi Grimm によるこの記事も、 Sandi Metz によるNothing is Somethingプレゼンテーションも、null オブジェクトの命名規則について言及していません。