blob: 7dee5c0efb9d231c591f89979c4598a7ac63a925 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
---
title: Abstraction (抽象化)
slug: Glossary/Abstraction
tags:
- Abstraction
- Coding
- CodingScripting
- Glossary
- Programming Language
translation_of: Glossary/Abstraction
---
<p>{{Glossary("Computer_Programming", "コンピュータープログラミング")}}における抽象化とは、複雑なソフトウェアシステムにおいて、複雑さを軽減し、また効率的な設計と実装を可能にする方法です。これはシステムの技術的な複雑さを、{{Glossary("API")}} の背後に隠します。</p>
<h2 id="Advantages_of_Data_Abstraction" name="Advantages_of_Data_Abstraction">データ抽象化の利点</h2>
<ul>
<li>ユーザーが低レベルコードを書くのを避けるのに役立つ。</li>
<li>コードの重複を避けて再利用性を上げる。</li>
<li>クラスの内部実装をユーザーに影響することなく独立して変更できる。</li>
<li>重要な詳細情報だけがユーザーに提供されているため、アプリケーションやプログラムのセキュリティ向上に役立つ。</li>
</ul>
<h2 id="Example" name="Example"><strong>例</strong></h2>
<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">class</span> <span class="class-name token">ImplementAbstraction</span> <span class="punctuation token">{</span>
<span class="comment token">// method to set values of internal members</span>
<span class="keyword token">set</span><span class="punctuation token">(</span>x<span class="punctuation token">,</span> y<span class="punctuation token">)</span> <span class="punctuation token">{</span>
<span class="keyword token">this</span><span class="punctuation token">.</span>a <span class="operator token">=</span> x<span class="punctuation token">;</span>
<span class="keyword token">this</span><span class="punctuation token">.</span>b <span class="operator token">=</span> y<span class="punctuation token">;</span>
<span class="punctuation token">}</span>
<span class="function token">display</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span>
console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="string token">'a = '</span> <span class="operator token">+</span> <span class="keyword token">this</span><span class="punctuation token">.</span>a<span class="punctuation token">)</span><span class="punctuation token">;</span>
console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="string token">'b = '</span> <span class="operator token">+</span> <span class="keyword token">this</span><span class="punctuation token">.</span>b<span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="punctuation token">}</span>
<span class="punctuation token">}</span>
<span class="keyword token">const</span> obj <span class="operator token">=</span> <span class="keyword token">new</span> <span class="class-name token">ImplementAbstraction</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
obj<span class="punctuation token">.</span><span class="function token">set</span><span class="punctuation token">(</span><span class="number token">10</span><span class="punctuation token">,</span> <span class="number token">20</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
obj<span class="punctuation token">.</span><span class="function token">display</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// a = 10</span>
<span class="comment token">// b = 20</span></code></pre>
<h2 id="Learn_more" name="Learn_more">詳細情報</h2>
<h3 id="General_knowledge" name="General_knowledge"><strong>基礎知識</strong></h3>
<ul>
<li>Wikipedia 上の記事 「{{interwiki("wikipedia", "抽象化_(計算機科学)")}}」</li>
</ul>
|