1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

オブジェクト指向について

Last updated at Posted at 2024-10-20

オブジェクト指向とは

工場のようにパーツ化して、完成品を組み立てるイメージ
同じパースは複製して使いまわしていく

三大原則

①カプセル化

処理を内部に閉じ込めて、外部からのアクセスを制限すること
Javaでいうprivate, public
電卓で例えるならキーがpublicで、電子回路がprivate

②継承

親クラスの特徴を子クラスに引き継がせること
親クラスの特徴を引き継ぐことができ、冗長性をなくすことができる
例えるなら、哺乳類クラスの子クラスは母乳で育つ的な

③多態性(ポリモーフィズム)

継承の応用で、親からの特徴は引き継ぎつつ、子クラスごとで内部の処理をかえる
たとえるなら魚類は水を泳ぐスキルがあるが、子クラスのマグロか鯉によって泳げる場所が異なる

オブジェクト、クラス、インスタンスの関係

オブジェクト⇒クラス、インスタンス合わせたもの。
クラス⇒オブジェクト(インスタンス)の金型。人が定義するが、実際にこれが動くわけではない。
インスタンス⇒クラスからPCに指示を出せるようにコンパイル化したもの

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?