# Rails のデザインパターン (Ruby on Rails) > Service objects、form objects、decorators、presenters、query objects、concerns - 22 面接問題 - Senior - [面接問題: Ruby on Rails](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions.md) ## 1. Rails における Service Object とは何ですか? **回答** Service Object は、複雑なビジネスロジック(通常は単一の操作)をカプセル化するプレーンな Ruby クラス(PORO)です。controller や model からロジックを抽出し、単一責任の原則(SRP)を保ちます。通常、service object は call や execute のような単一の public メソッドを公開するため、テストや再利用が容易になります。 ## 2. controller にロジックを置く代わりに Service Object を使う主な利点は何ですか? **回答** 主な利点はテスタビリティと再利用性です。Service Object は独立した Ruby クラスであり、controller の完全な HTTP コンテキストをシミュレートせずに単体で簡単にテストできます。さらに、同じロジックをコードの重複なしにさまざまな場所(controller、job、console)から呼び出せます。 ## 3. 明確な命名規則で Service Object をどのように構成しますか? **回答** 推奨される規則は、実行されるアクションを反映するように、動詞のあとに名詞を続けることです(例:CreateUser、ProcessPayment、SendInvitation)。サービスは唯一のエントリーポイントとして call メソッドを公開し、UserCreator.call(params) または UserCreator.new(params).call で呼び出せます。この規則によりコードは自己文書化され、予測しやすくなります。 ## さらに19問利用可能 - Form Object とは何で、いつ使いますか? - ActiveRecord のバリデーションを利用するために、Form Object にインクルードすべき Ruby モジュールはどれですか? 無料で登録: https://sharpskill.dev/ja/login ## その他のRuby on Rails面接トピック - [Rubyの基礎](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/ruby-basics.md): 25問, Junior - [Rubyのオブジェクト指向プログラミング](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/ruby-oop.md): 20問, Junior - [Rails の基礎](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-fundamentals.md): 18問, Junior - [Routing & Controllers](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/routing-controllers.md): 22問, Junior - [ActiveRecord の基礎](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/active-record-basics.md): 25問, Junior - [Views と ERB テンプレート](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/views-erb-templates.md): 20問, Junior - [ActiveRecord の関連付け](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/active-record-associations.md): 24問, Mid-Level - [高度なActiveRecordクエリ](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/active-record-queries.md): 28問, Mid-Level - [Rails フォーム](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-forms.md): 20問, Mid-Level - [認証と認可](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/authentication-authorization.md): 22問, Mid-Level - [モダンな Asset Pipeline とフロントエンド](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-asset-pipeline.md): 18問, Mid-Level - [Rails APIモード](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-api-mode.md): 20問, Mid-Level - [RSpecによるテスト](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-testing-rspec.md): 24問, Mid-Level - [ActiveJob & Background Jobs](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/active-job-background-jobs.md): 20問, Mid-Level - [ActionCable & WebSockets](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/action-cable-websockets.md): 18問, Mid-Level - [ActionMailer](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/action-mailer.md): 18問, Mid-Level - [ActiveStorage](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/active-storage.md): 20問, Mid-Level - [キャッシュ戦略](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/caching-strategies.md): 20問, Mid-Level - [高度なマイグレーション](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/database-migrations-advanced.md): 20問, Mid-Level - [Rails Engines とモジュラーアプリ](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-engines-modular-apps.md): 18問, Senior - [パフォーマンス最適化](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/performance-optimization.md): 26問, Senior - [Rubyのメタプログラミング](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/ruby-metaprogramming.md): 20問, Senior - [Rails のセキュリティ](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-security.md): 22問, Senior - [Rails での GraphQL](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/graphql-rails.md): 20問, Senior - [デプロイと本番環境](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-deployment-production.md): 20問, Senior - [Monitoring & Logging](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/monitoring-logging.md): 20問, Senior - [Rails アップグレード戦略](https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-upgrade-strategies.md): 18問, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/ja/technologies/ruby-on-rails/interview-questions/rails-design-patterns