RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Actor Action Object

Learn how procedural code can be used in conjunction with object-oriented paradigm in your Rails projects Actor Action Object in Rails Projects

Comments

In terms of purpose it would be almost like a service object, right?

The use cases are named with the name of the corresponding use case. The file name is not a class name but a verb. Each use case is encapsulated as a stateless method. It is not an object. So you cannot say it is a ‘Service Object’ because it is not an object. It does not have any state.

It resembles a service object in the sense, it follows the accept input, perform work, return result structure. It is also similar to a ‘service’ in the sense, it does describe system interactions. It usually will involve more than one object in our application.

I don’t name classes with verbs, looks like developers are not following the basics of OO design. They try to fit square peg round hole. Here is an example : https://netguru.co/blog/service-objects-in-rails-will-help where he names an object as CreateInvoice. This is wrong.

This post : http://brewhouse.io/blog/2014/04/30/gourmet-service-objects.html says Service Object does only one thing. My use case handler does more than just one thing.

When you find yourself violating the basic principles of OO design, it is a sign that your design needs improvement. There is no need to hide the use cases in your system. Make them explicit. Use cases are procedural in nature. It will cut across objects in different layers of your system. We don’t have to make them an object.

This article here : https://blog.engineyard.com/2014/keeping-your-rails-controllers-dry-with-services uses Service Object for credit card processing. I would use the Gateway Object (An object that encapsulates access to an external system or resource) as discussed by Martin Fowler in his P of EAA : http://martinfowler.com/eaaCatalog/gateway.html

There seems to be lot of confusion about Service Objects because developers are not following the standard terminology.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in