You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/09-classes/04-private-protected-properties-methods/article.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -283,40 +283,40 @@ class User {
283
283
این برای فیلدهای خصوصی غیر ممکن است: `this['#name']` کار نمیکند. این یک محدودیت سینتکسی است تا حریم اطمینان حاصل کند.
284
284
````
285
285
286
-
## Summary
286
+
## خلاصه
287
287
288
-
In terms of OOP, delimiting of the internal interface from the external one is called [encapsulation](https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)).
288
+
از نظر برنامهنویسی شیءگرا، جدا کردن رابط درونی از بیرونی را [کپسولهسازی](https://fa.wikipedia.org/wiki/پوشاندن_(علم_رایانه)) میگویند.
289
289
290
-
It gives the following benefits:
290
+
این مزایا را به ما میدهد:
291
291
292
-
Protection for users, so that they don't shoot themselves in the foot
293
-
: Imagine, there's a team of developers using a coffee machine. It was made by the "Best CoffeeMachine" company, and works fine, but a protective cover was removed. So the internal interface is exposed.
292
+
حفاظت از کاربران، تا آنها خودشان را در مخمصه نیاندازند
293
+
: تصور کنید، تیمی از توسعهدهندگان در حال استفاده از قهوهساز هستند. این دستگاه توسط شرکت «بهترین قهوهساز» ساخته شده و به خوبی کار میکند، اما یک پوشش محافظ برداشته شد. پس رابط درونی افشاء شده است.
294
294
295
-
All developers are civilized -- they use the coffee machine as intended. But one of them, John, decided that he's the smartest one, and made some tweaks in the coffee machine internals. So the coffee machine failed two days later.
295
+
تمام توسعهدهندگان متمدن هستند -- آنها از قهوهساز همانطور که توقع میرود استفاده میکنند. اما یکی از آنها، John، تصمیم گرفته است که باهوشترین است و درون قهوهساز تغییراتی ایجاد کرد. قهوهساز دو روز بعد از کار میافتد.
296
296
297
-
That's surely not John's fault, but rather the person who removed the protective cover and let John do his manipulations.
297
+
قطعا این تقصیر John نیست بلکه تقصیر کسی است که پوشش محافظ را برداشت و اجازه داد که John قهوهساز را دستکاری کند.
298
298
299
-
The same in programming. If a user of a class will change things not intended to be changed from the outside -- the consequences are unpredictable.
299
+
همچین چیزی در برنامهنویسی هم وجود دارد. اگر یک کاربرِ کلاس چیزهایی را که قرار نیست تغییر کنند را از بیرون تغییر دهد -- عواقب آن غیر قابل پیشبینی هستند.
300
300
301
-
Supportable
302
-
: The situation in programming is more complex than with a real-life coffee machine, because we don't just buy it once. The code constantly undergoes development and improvement.
301
+
قابل پشتیبانی
302
+
: این وضعیت در برنامهنویسی پیچیدهتر از یک قهوهساز در زندگی واقعی است چون ما فقط آن را یک بار نمیخریم. کد دائما در توسعه و پیشرفت است.
303
303
304
-
**If we strictly delimit the internal interface, then the developer of the class can freely change its internal properties and methods, even without informing the users.**
304
+
**اگر ما به صورت سختگیرانه رابط درونی را جداسازی کنیم، سپس توسعهدهندهی کلاس آزادانه میتواند ویژگیها و متدهای درون آن را تغییر دهد، حتی بدون اینکه کاربران را خبردار کند.**
305
305
306
-
If you're a developer of such class, it's great to know that private methods can be safely renamed, their parameters can be changed, and even removed, because no external code depends on them.
306
+
اگر شما توسعهدهنده چنین کلاسی باشید، این عالی است که بتوانید متدهای خصوصی را با خیال راحت تغییر نام دهید، پارامترهای آنها را تغییر دهید و حتی حذف کنید، چون هیچ کد بیرونی به آنها وابسته نیست.
307
307
308
-
For users, when a new version comes out, it may be a total overhaul internally, but still simple to upgrade if the external interface is the same.
308
+
برای کاربران، زمانی که نسخهای جدید منتشر میشود، ممکن است از درون تعمیرات اساسی نیاز داشته باشد اما اگر رابط بیرونی یکسان باشد هنوز برای ارتقا دادن ساده است.
309
309
310
-
Hiding complexity
311
-
: People adore using things that are simple. At least from outside. What's inside is a different thing.
310
+
پنهان کردن پیچیدگی
311
+
: مردم عاشق استفاده از چیزهای ساده هستند. حداقل از بیرون. چیزی که درون وجود دارد موضوع متفاوتی است.
312
312
313
-
Programmers are not an exception.
313
+
برنامهنویسان استثنا نیستند.
314
314
315
-
**It's always convenient when implementation details are hidden, and a simple, well-documented external interface is available.**
315
+
**همیشه زمانی که جزئیات پیادهسازی پنهان هستند و یک رابط بیرونی ساده و به خوبی مستند شده وجود دارد کار راحت است.**
316
316
317
-
To hide an internal interface we use either protected or private properties:
317
+
برای پنهانسازی یک رابط درونی میتوانیم یا از ویژگیهای محافظتشده استفاده کنیم یا ویژگیهای خصوصی:
318
318
319
-
-Protected fields start with `_`. That's a well-known convention, not enforced at the language level. Programmers should only access a field starting with `_` from its class and classes inheriting from it.
320
-
-Private fields start with `#`. JavaScript makes sure we can only access those from inside the class.
319
+
-فیلدهای محافظتشده با `_` شروع میشوند. این یک قرارداد شناختهشده است و در سطح زبان اجرایی نشدهاند. برنامهنویسان فقط باید از درون کلاس و کلاسهایی که از آن ارث میبرند، به فیلدی که با `_` شروع میشود دسترسی پیدا کنند.
320
+
-فیلدهای خصوصی با `#` شروع میشوند. جاوااسکریپت مطمئن میشود که ما فقط از درون کلاس بتوانیم به آنها دسترسی پیدا کنیم.
321
321
322
-
Right now, private fields are not well-supported among browsers, but can be polyfilled.
322
+
در حال حاضر، فیلدهای خصوصی به خوبی در میان مرورگرها پشتیبانی نمیشوند اما میتوان برای آنها پلیفیل ساخت.
0 commit comments