DEV Community

Discussion on: Template design pattern in Ruby. Any reason not to use a module instead of a superclass?

Collapse
 
dfockler profile image
Dan Fockler • Edited

You're definitely right, abstract classes are not meant to be instantiated. That does not mean that the methods they implement are clean from pulling in dependencies, and when mixins/modules end up depending on their child classes (same with abstract classes), then you have problems.

module Commentable
  def comment(text)
    # You now depend on methods of the child class
    self.comments << text 
  end
end

class Post
  include Commentable
end