For rails applications: does there exist a naming convention for naming your null objects that are mapped to 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 NullBlog
conventional?
Neither this article by Avdi Grimm nor the Nothing is Something presentation by Sandi Metz mentioned any null object naming convention.
There is no mainstream convention as of now. Likely because the Null Object Pattern itself is not seeing widespread use yet. The only reference to a naming guideline that I have come across comes from the ThoughBot Style Guide, which uses it as an example of a naming rule:
Prefer naming classes after domain concepts rather than patterns they implement (e.g. Guest vs NullUser, CachedRequest vs RequestDecorator).
In your case, it would be a matter of finding the "domain language" for a "null blog." The best method I've found for finding these terms is to simply talk to domain users about the topic, and note down any nouns they use. This approach was outlined in the book Object Thinking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With