https://wiki.hsoub.com/index.php?title=Refactoring/self_encapsulate_field&feed=atom&action=history
Refactoring/self encapsulate field - تاريخ المراجعة
2024-03-29T15:36:35Z
تاريخ التعديل لهذه الصفحة في الويكي
MediaWiki 1.35.0
https://wiki.hsoub.com/index.php?title=Refactoring/self_encapsulate_field&diff=28030&oldid=prev
جميل-بيلوني: مراجعة وتدقيق.
2019-03-02T09:44:02Z
<p>مراجعة وتدقيق.</p>
<table class="diff diff-contentalign-right diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="ar">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">→ مراجعة أقدم</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">مراجعة 09:44، 2 مارس 2019</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l40" >سطر 40:</td>
<td colspan="2" class="diff-lineno">سطر 40:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>}</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></syntaxhighlight>في لغة TypeScript:<syntaxhighlight lang="typescript"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">class Range {</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> private low: number</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> private high: number;</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> includes(arg: number): boolean {</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> return arg >= low && arg <= high;</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> }</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">}</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l91" >سطر 91:</td>
<td colspan="2" class="diff-lineno">سطر 99:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>}</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>}</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></syntaxhighlight>في لغة TypeScript:<syntaxhighlight lang="typescript"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">class Range {</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> private low: number</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> private high: number;</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> includes(arg: number): boolean {</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> return arg >= getLow() && arg <= getHigh();</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> }</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> getLow(): number {</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> return low;</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> }</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> getHigh(): number {</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> return high;</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> }</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">}</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></syntaxhighlight></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l106" >سطر 106:</td>
<td colspan="2" class="diff-lineno">سطر 128:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== آلية الحل ==</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== آلية الحل ==</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div># إنشاء تابعٍ <code>getter</code> (وربما <code>setter</code> إن دعت الحاجة) للحقل، وإمّا أن يكون مُحدِّد الوصول للتابع من النوع المحمي (protected) أو العام (public).</div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div># إنشاء تابعٍ <ins class="diffchange diffchange-inline">جالب </ins><code>getter</code> (وربما <ins class="diffchange diffchange-inline">ضابط </ins><code>setter</code> إن دعت الحاجة) للحقل، وإمّا أن يكون مُحدِّد الوصول للتابع من النوع المحمي (protected) أو العام (public).</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># تبديل كلِّ وصولٍ مباشرٍ للحقل إلى استدعاءٍ للتابع <code>getter</code> أو <code>setter</code> بحسب الحاجة.</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># تبديل كلِّ وصولٍ مباشرٍ للحقل إلى استدعاءٍ للتابع <code>getter</code> أو <code>setter</code> بحسب الحاجة.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l115" >سطر 115:</td>
<td colspan="2" class="diff-lineno">سطر 137:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* [https://refactoring.guru/self-encapsulate-field صفحة توثيق التغليف الداخليّ للحقول في موقع refactoring.guru.]</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>* [https://refactoring.guru/self-encapsulate-field صفحة توثيق التغليف الداخليّ للحقول في موقع refactoring.guru.]</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[تصنيف:Refactoring]]</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[تصنيف:Refactoring]]</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[تصنيف:Refactoring Techniques]]</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[تصنيف:Refactoring Organizing Data]]</ins></div></td></tr>
</table>
جميل-بيلوني
https://wiki.hsoub.com/index.php?title=Refactoring/self_encapsulate_field&diff=23214&oldid=prev
جميل-بيلوني في 09:09، 12 نوفمبر 2018
2018-11-12T09:09:20Z
<p></p>
<table class="diff diff-contentalign-right diff-editfont-monospace" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="ar">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">→ مراجعة أقدم</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">مراجعة 09:09، 12 نوفمبر 2018</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1" >سطر 1:</td>
<td colspan="2" class="diff-lineno">سطر 1:</td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><noinclude>{{DISPLAYTITLE:<del class="diffchange diffchange-inline">إخفاء التفويض </del>(<del class="diffchange diffchange-inline">Hide Delegate</del>)}}</noinclude></div></td><td class='diff-marker'>+</td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><noinclude>{{DISPLAYTITLE:<ins class="diffchange diffchange-inline">التغليف الداخلي للحقول </ins>(<ins class="diffchange diffchange-inline">Self Encapsulate Fields</ins>)}}</noinclude></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>ملاحظة قبل البدء: تختلف هذه التقنية عن تقنية تغليف الحقول (Encapsulate Field) من حيث أنّها تُستخدَم لتغليف الحقول الخاصّة (أي المُحدَّدة بالكلمة المفتاحيّة private).</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>ملاحظة قبل البدء: تختلف هذه التقنية عن تقنية تغليف الحقول (Encapsulate Field) من حيث أنّها تُستخدَم لتغليف الحقول الخاصّة (أي المُحدَّدة بالكلمة المفتاحيّة private).</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
</table>
جميل-بيلوني
https://wiki.hsoub.com/index.php?title=Refactoring/self_encapsulate_field&diff=23213&oldid=prev
جميل-بيلوني: إنشاء الصفحة. هذه الصفحة من مساهمات "نور تامر".
2018-11-12T09:08:44Z
<p>إنشاء الصفحة. هذه الصفحة من مساهمات "نور تامر".</p>
<p><b>صفحة جديدة</b></p><div><noinclude>{{DISPLAYTITLE:إخفاء التفويض (Hide Delegate)}}</noinclude><br />
ملاحظة قبل البدء: تختلف هذه التقنية عن تقنية تغليف الحقول (Encapsulate Field) من حيث أنّها تُستخدَم لتغليف الحقول الخاصّة (أي المُحدَّدة بالكلمة المفتاحيّة private).<br />
<br />
== المشكلة ==<br />
الوصول المباشر إلى الحقول الخاصّة (private fields) داخل الصنف (class).<br />
<br />
== الحل ==<br />
إنشاء تابعي الوصول getter و setter للحقل الخاصّ ومنع الوصول إليه إلا عبرهما.<br />
<br />
=== مثال ===<br />
<br />
==== قبل إعادة التصميم ====<br />
يحتوي الصنف <code>Range</code> على الحقلين <code>low</code> و <code>high</code> من النوع الخاص (private) ونلاحظ الوصول إليهما مباشرةً داخل التابع <code>includes</code> في الشيفرة الآتية:<br />
<br />
في لغة Java:<syntaxhighlight lang="java"><br />
class Range {<br />
private int low, high;<br />
boolean includes(int arg) {<br />
return arg >= low && arg <= high;<br />
}<br />
}<br />
<br />
</syntaxhighlight>في لغة C#:<syntaxhighlight lang="c#"><br />
class Range <br />
{<br />
private int low, high;<br />
<br />
bool Includes(int arg) <br />
{<br />
return arg >= low && arg <= high;<br />
}<br />
}<br />
<br />
</syntaxhighlight>في لغة PHP:<syntaxhighlight lang="php"><br />
private $low;<br />
private $high;<br />
<br />
function includes($arg) {<br />
return $arg >= $this->low && $arg <= $this->high;<br />
}<br />
<br />
</syntaxhighlight><br />
<br />
==== بعد إعادة التصميم ====<br />
أُضيف تابع الوصول <code>getter</code> للحقلين <code>low</code> و <code>high</code> بهدف إجراء التغليف الداخليّ لهما، وأصبح الوصول لهما في التابع <code>includes</code> عبر تابعي الوصول المُنشَأين، لتصبح الشيفرة كما يلي:<br />
<br />
في لغة Java:<syntaxhighlight lang="java"><br />
class Range {<br />
private int low, high;<br />
boolean includes(int arg) {<br />
return arg >= getLow() && arg <= getHigh();<br />
}<br />
int getLow() {<br />
return low;<br />
}<br />
int getHigh() {<br />
return high;<br />
}<br />
}<br />
<br />
</syntaxhighlight>في لغة C#:<syntaxhighlight lang="c#"><br />
class Range <br />
{<br />
private int low, high;<br />
<br />
int Low {<br />
get { return low; }<br />
}<br />
int High {<br />
get { return high; }<br />
}<br />
<br />
bool Includes(int arg) <br />
{<br />
return arg >= Low && arg <= High;<br />
}<br />
}<br />
<br />
</syntaxhighlight>في لغة PHP:<syntaxhighlight lang="php"><br />
private $low;<br />
private $high;<br />
<br />
function includes($arg) {<br />
return $arg >= $this->getLow() && $arg <= $this->getHigh();<br />
}<br />
function getLow() {<br />
return $this->low;<br />
}<br />
function getHigh() {<br />
return $this->high;<br />
}<br />
<br />
</syntaxhighlight><br />
<br />
== لم إعادة التصميم؟ ==<br />
قد لا يوفِّر الوصول المباشر إلى الحقل الخاصِّ المرونة الكافية ببعض الأحيان، فلربما تحتاج إلى تهيئة قيمة الحقل (initiate) عند أول استعلامٍ (query) يُجرَى على الحقل، أو تنفيذِ عمليّات معيّنة على القيم الجديدة المُسندة إلى الحقل حال إسنادها، أو القيام بكلِّ هذا في الأصناف الفرعيّة (subclasses) لهذا الصنف.<br />
<br />
== فوائد تطبيق الحل ==<br />
* تحقيق الوصول غير المباشر للحقل (عبر تابعي الوصول getter و setter)، وبهذا تضمن مرونةً أكبر للتعامل مع الحقل الخاصّ، إذ أصبح بالإمكان:<br />
# إجراء العمليات المعقَّدة عند الحصول على قيمة الحقل أو تعديلها، ومن السهل كذلك القيام بالتهيئة الكسولة (lazy initialization) والتأكد من قيمة الحقل (value validation) داخل تابعي الوصول getter وsetter.<br />
# إعادة تعريف التابعين getter و setter في الأصناف الفرعيّة (subclasses).<br />
* قد لا ترى بضرورة إنشاء تابع setter للحقل المطلوب، وعندها سيقتصر إسناد القيم لهذا الحقل على الباني (constructor) فقط، أي سيصبح الحقل غير قابلٍ للتغيير طيلة حياة الكائن (object).<br />
<br />
== مساوئ تطبيق الحل ==<br />
لا شكَّ بأنّ الشيفرة تصبح أبسط بالاعتماد على الوصول المباشر للحقل بدلًا من تغليفه، ولكنّه ليس الخيار الأفضل من ناحية المرونة (flexibility).<br />
<br />
== آلية الحل ==<br />
# إنشاء تابعٍ <code>getter</code> (وربما <code>setter</code> إن دعت الحاجة) للحقل، وإمّا أن يكون مُحدِّد الوصول للتابع من النوع المحمي (protected) أو العام (public).<br />
# تبديل كلِّ وصولٍ مباشرٍ للحقل إلى استدعاءٍ للتابع <code>getter</code> أو <code>setter</code> بحسب الحاجة.<br />
<br />
== انظر أيضًا ==<br />
* [[Refactoring/replace data value with object|تبديل قيم البيانات إلى كائنات]].<br />
<br />
== مصادر ==<br />
* [https://refactoring.guru/self-encapsulate-field صفحة توثيق التغليف الداخليّ للحقول في موقع refactoring.guru.]<br />
[[تصنيف:Refactoring]]</div>
جميل-بيلوني