data encapsulation غليف البيانات ---------- تعدد الأشكال ((polymorphism
Data encapsulation, sometimes referred to as data hiding, is the mechanism whereby the implementation details of a class are kept hidden from the user. تغليف البيانات ، التي يشار إليها أحيانا إخفاء البيانات ، هو آلية يتم بموجبها أخفي تفاصيل تنفيذ فئة من المستخدم. The user can only perform a restricted set of operations on the hidden members of the class by executing special functions commonly called methods . ويمكن للمستخدم فقط تنفيذ مجموعة محدودة من العمليات على أعضاء المخفية من الطبقة عن طريق تنفيذ المهام الخاصة أساليب يسمى بشكل شائع. The actions performed by the methods are determined by the designer of the class, who must be careful not to make the methods either overly flexible or too restrictive. وتحدد الإجراءات التي تقوم بها وسائل من قبل المصمم للفئة ، الذي يجب أن تحرص على عدم جعل أساليب مرنة إما مفرطة أو ضيقة للغاية. This idea of hiding the details away from the user and providing a restricted, clearly defined interface is the underlying theme behind the concept of an abstract data type . هذه الفكرة من الاختباء بعيدا عن تفاصيل المستخدم وتوفير مقيدة ، واجهة واضحة المعالم هو الموضوع الأساسي وراء مفهوم نوع بيانات مجردة.
The advantage of using data encapsulation comes when the implementation of the class changes but the interface remains the same. وميزة استخدام البيانات التغليف عندما يأتي تنفيذ التغييرات واجهة الطبقة لكن لا يزال هو نفسه. For example, to create a stack class which can contain integers, the designer may choose to implement it with an array, which is hidden from the user of the class. على سبيل المثال ، لإنشاء مكدس الطبقة التي يمكن أن تحتوي على أعداد صحيحة ، قد يختار مصمم على تنفيذه مع مجموعة ، التي كلها من المستخدم للفئة. The designer then writes the push() and pop() methods which puts integers into the array and removes them from the array respectively. المصمم ثم يكتب دفع () والبوب () الذي يضع أساليب صحيحة في مجموعة ويزيل لهم من الصفيف على التوالي. These methods are made accessible to the user. وتتكون هذه الأساليب للوصول إلى المستخدم. Should an attempt be made by the user to access the array directly, a compile time error will result. يجب محاولة بذل من قبل المستخدم للوصول إلى مجموعة مباشرة ، ترجمة خطأ وقت سيؤدي. Now, should the designer decide to change the stack's implementation to a linked list, the array can simply be replaced with a linked list and the push() and pop() methods rewritten so that they manipulate the linked list instead of the array. الآن ، ينبغي للمصمم تقرر تغيير المكدس للتنفيذ إلى قائمة ربط يمكن ببساطة ، مجموعة استبداله مع قائمة مرتبطة ودفع () والبوب () أساليب إعادة كتابة بحيث التلاعب في قائمة مرتبطة بدلا من الصفيف. The code which the user has written to manipulate the stack is still valid because it was not given direct access to the array to begin with. رمز التي بعثت للمستخدم التعامل مع مكدس لا يزال صالحا لأن هذا الأمر لم نعطه الوصول المباشر إلى مجموعة لتبدأ.
The concept of data encapsulation is supported in C++ through the use of the public , protected and private keywords which are placed in the declaration of the class. بدعم من البيانات التغليف هو مفهوم في سي + + من خلال استخدام وحمايتها وخاصة الكلمات الرئيسية العامة التي يتم وضعها في إعلان الفئة. Anything in the class placed after the public keyword is accessible to all the users of the class; elements placed after the protected keyword are accessible only to the methods of the class or classes derived from that class; elements placed after the private keyword are accessible only to the methods of the class. أي شيء في فئة وضعت بعد الكلمة العامة هي في متناول جميع مستخدمي الفئة ؛ العناصر وضعت بعد الكلمة المحمية هي فقط للوصول إلى أساليب الفئة أو الفئات المشتقة من تلك الفئة ؛ العناصر وضعت بعد الكلمة خاصة يمكن الوصول إليها فقط إلى أساليب الفئة.
As a convention, calling a method of an object instantiated from a class is commonly referred to as sending a message to that object. باعتبارها الاتفاقية ، استدعاء أسلوب كائن مثيل من فئة ويشار إلى إرسال كرسالة لهذا الكائن.