v# User service object when: # 1- The action is complex # 2- The action reaches across multiple models (e.g. an e-commerce purchase using Order, CreditCard and Customer objects) # 3- The action interacts with an external service (e.g. posting to social networks) # 4- The action is not a core concern of the underlying model (e.g. sweeping up outdated data after a certain time period). # 5- There are multiple ways of performing the action (e.g. authenticating with an access token or password). class UserCSVDump < Struct.new(:users) def csv CSV.generate do |csv| csv << %w[id username email] users.each do |user| csv << [user.id, user.username, user.email] end end end end # Another example would be a class to manage authentication