5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Railsの設計思想「CoC」について

Last updated at Posted at 2021-05-06

##はじめに

まずRailsには設計思想として3つ強く打ち出しています。

  1. CoC (Convention over Configuration)
  2. DRY (Don’t Repeat Yourself)
  3. REST(Representational State Transfer)

今回は1のCoCについて解説したいと思います。

##CoCとは
直訳すると「設定より規約」という意味になります。例えばユーザー情報を表現するモデルをUserモデルとした場合、Railsでは以下の様なルールに則って開発します。

  • データベースのテーブル名はモデル名の複数形にする(Users)
  • /usersというURLはユーザーの一覧を表す
  • ユーザーID:1のユーザー情報を表すURLは/users/1になる

上記の様なルールで書くとそれぞれに細かく設定を紐付ける作業を省略できます。
「便利ですね〜」
またこれらの規約に従うとプログラム内に規律が生まれ以下の様な、メリットもあります。

  • 多くの設定ファイルを書かなくて良い
  • 共通のルールがあることで他のエンジニアとスムーズなコミュニケーションが取れる
5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?