مقدمة في البرمجة الكائنية بـ Python
17 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

ما المقصود بالبرمجة الكائنية التوجه (OOP)؟

  • أسلوب برمجي يعتمد على الدوال فقط
  • أسلوب برمجي يستخدم فقط في تطبيقات الويب
  • أسلوب برمجي يعتمد على العناصر والكائنات (correct)
  • أسلوب برمجي يتطلب كتابة كود معقد

ما هي الخاصية الأساسية للفئة (class) في البرمجة الكائنية التوجه؟

  • تحتوي على متغيرات عشوائية
  • تعمل كقالب لإنشاء الكائنات (correct)
  • تستطيع استخدام الذاكرة العشوائية فقط
  • تحدد كيفية تنفيذ البرامج الخارجية

كيف يمكن إنشاء كائن من فئة في بايثون؟

  • بطرق إرثية فقط
  • باستخدام الكلمة المحجوزة 'object'
  • بالاتصال باسم الفئة كما لو كانت دالة (correct)
  • بتنفيذ وظيفة محددة داخل فئة

ما وظيفة الدالة الخاصة __init__ في بايثون؟

<p>تعمل كمنشئ وتقوم بتهيئة سمات الكائن (D)</p> Signup and view all the answers

ما هي خاصية الوراثة (Inheritance) في البرمجة الكائنية التوجه؟

<p>تسمح بإنشاء فئات جديدة بناءً على فئات موجودة (D)</p> Signup and view all the answers

أي مما يلي يمثل الف polymorphism في البرمجة الكائنية التوجه؟

<p>استخدام نفس الاسم للدوال مع تنفيذات مختلفة (C)</p> Signup and view all the answers

كيف يتم التحكم في الوصول إلى البيانات (attributes) في البرمجة الكائنية التوجه؟

<p>من خلال الأساليب الخاصة بفئة معينة (C)</p> Signup and view all the answers

كيف يمكن الوصول إلى سمة كائن في بايثون؟

<p>باستخدام نقطة الوصول واسم السمة (A)</p> Signup and view all the answers

ما هو المقصود بمفهوم التجريد في البرمجة كائنية التوجه؟

<p>تبسيط الأنظمة المعقدة من خلال إخفاء التفاصيل الداخلية (A)</p> Signup and view all the answers

ما هو أحد فوائد استخدام البرمجة كائنية التوجه في بايثون؟

<p>تسهيل إدارة المشاريع المعقدة (C)</p> Signup and view all the answers

كيف تتعامل بايثون مع مفاتيح الوصول (Access Modifiers)؟

<p>تستخدم الاتفاقيات لتحديد الخصوصية (A)</p> Signup and view all the answers

ما هي إحدى الطرق التي يمكن بها التحقق من صحة المدخلات عند الوصول إلى السمات؟

<p>استخدام طرق الوصول (getters and setters) (A)</p> Signup and view all the answers

ما هي الميزة الرئيسية لقوائم بايثون أو القواميس أو المجموعات بهذا الشكل؟

<p>هي أمثلة على الفئات وتحتوي على طرق وسمات (D)</p> Signup and view all the answers

ما هو السبب وراء استخدام معالجة الاستثناءات في البرمجة كائنية التوجه؟

<p>لتسهيل معالجة الأخطاء ضمن وظائف الكائنات (A)</p> Signup and view all the answers

ما هو أحد الأغراض الرئيسية لمفاهيم المولدات (Generators) في بايثون؟

<p>تسهيل التعامل مع تكرارات البيانات الكبيرة (C)</p> Signup and view all the answers

ما هو أحد العناصر الأساسية التي تعزز قابلية إعادة استخدام الكود في البرمجة كائنية التوجه؟

<p>تعدد النماذج (Polymorphism) (B)</p> Signup and view all the answers

<h1>=</h1> <h1>=</h1> Signup and view all the answers

Flashcards

التجريد (Abstraction)

إخفاء التفاصيل الداخلية المعقدة لنظام ما ، وعرض المعلومات الأساسية فقط للمستخدم. تعمل فئات وأشياء البرمجة الموجهة للكائنات (OOP) كطبقة تجريد.

الوصول إلى السمات (Getting and Setting Attributes)

تُستخدم طرق الوصول إلى السمات للتحكم في كيفية الوصول إلى البيانات وتأكيد صحتها عند الضرورة.

البرمجة الموجهة للكائنات (OOP) في بايثون

توفر فئات وأشياء OOP طريقة لتنظيم البرنامج إلى وحدات مترابطة. وتوفر هذه الفئات خصائص وسلوكيات الكائنات.

مزايا البرمجة الموجهة للكائنات (OOP) في بايثون

تؤدي OOP إلى تنظيم أفضل للكود وتسهل إعادة الاستخدام والحفاظ على الكود. كما تساعد في جعل الكود أكثر قابلية للقراءة وسهولة توسع.

Signup and view all the flashcards

بنية بيانات بايثون المُدمجة (Built-in Data Structures)

بنية البيانات المُدمجة في بايثون، مثل القوائم والقواميس والأزواج، هي أمثلة على الفئات.

Signup and view all the flashcards

معدلات الوصول (Access Modifiers)

تستخدم لضبط الوصول إلى سمات ووظائف الفئات.

Signup and view all the flashcards

معالجة الاستثناءات (Exception Handling)

يمكن استخدام معالجة الاستثناءات مع OOP لمعالجة الأخطاء داخل دوال الفئات بشكل محدد.

Signup and view all the flashcards

الكرّارات والمُنشئات (Iterators and Generators)

تُستخدم الكرّارات والمُنشئات ضمن OOP لإنشاء كائنات قابلة للتكرار.

Signup and view all the flashcards

برمجة موجهة للكائنات (OOP)

نموذج برمجة يعتمد على مفهوم "الكائنات" التي تُخزّن البيانات (السمات) والرموز (الأساليب) للتلاعب بالبيانات. Python تدعم OOP من خلال الفئات والكائنات، مما يسمح بكتابة كود مُجَدِّد وأكثر قابلية للتوسع.

Signup and view all the flashcards

فئة

خطة أو نموذج لإنشاء كائنات. تحدّد خصائص (السمات) وأفعال (الأساليب) التي ستتمتع بها كائنات تلك الفئة. يتم تعريف الفئات باستخدام الكلمة المفتاحية class، يليها اسم الفئة (عادةً ما يُكتب بحرف كبير).

Signup and view all the flashcards

كائن

مثال أو نسخة من فئة. عند استدعاء اسم فئة كوظيفة، يتم إنشاء كائن من تلك الفئة.

Signup and view all the flashcards

الصفات (السمات)

البيانات المخزنة في كائن. تحدّد خصائص الكائن.

Signup and view all the flashcards

الأساليب (الوظائف)

الأفعال التي يمكن أن يُنفّذها كائن. تحدّد ما يمكن أن يفعله الكائن.

Signup and view all the flashcards

المُنشئ (__init__)

طريقة خاصة تُدعى تلقائيًا عند إنشاء كائن جديد. تُستخدم لتهيئة صِفات الكائن عند إنشائه.

Signup and view all the flashcards

الميراث

ميزة تُمكّن من إنشاء فئات جديدة (فئات مُشتَقَة) بناءً على فئات موجودة (فئات أساسية). الفئة المُشتَقَة ترث صِفات وأساليب الفئة الأساسية، مع إمكانية إضافة صِفات وأساليب خاصة بها.

Signup and view all the flashcards

التعدد الشكلي (Polymorphism)

ميزة تتيح التعامل مع كائنات من فئات مختلفة كأنها من نفس النوع (فئة مشتركة). يمكن لأساليب بنفس الاسم أن تتضمن تنفيذاً مختلفًا في فئات مختلفة.

Signup and view all the flashcards

Study Notes

Introduction to Object-Oriented Programming (OOP) in Python

  • Object-oriented programming (OOP) is a programming paradigm built on the concept of "objects," containing both data (attributes) and code (methods) to manipulate that data.
  • Python supports OOP through classes and objects, enabling modular, reusable code.

Defining Classes

  • A class acts as a blueprint for creating objects, defining attributes and methods objects will possess.
  • Classes are defined using the class keyword, followed by the class name (usually capitalized).
  • Example:
class Dog:
    def __init__(self, name, breed):  # Constructor
        self.name = name
        self.breed = breed

    def bark(self):   # Method
        print("Woof!")

Creating Objects

  • An object is an instance of a class. Creating an object involves calling the class name as a function.
  • Example:
my_dog = Dog("Buddy", "Golden Retriever")
  • This creates my_dog, an object of the Dog class.

Attributes and Methods

  • Attributes store data associated with an object.
  • Methods define actions an object can perform.
  • Accessing attributes:
print(my_dog.name)  # Output: Buddy
  • Calling methods:
my_dog.bark()    # Output: Woof!

Constructors (__init__)

  • The __init__ method, a special constructor, is automatically called when creating a new object; it initializes object attributes.

Inheritance

  • Inheritance allows creating new classes (derived) from existing ones (base).
  • A derived class inherits attributes and methods from its base class.
  • It can also add its own specific attributes and methods.
  • Example:
class GoldenRetriever(Dog):
    def __init__(self, name):
        super().__init__(name, "Golden Retriever")  # Call base class constructor

my_golden = GoldenRetriever("Max")  # Output: No error, inherits everything

Polymorphism

  • Polymorphism enables objects from different classes to be treated as objects of a common type.
  • Methods sharing the same name can have different implementations in each class.
  • Example:
class Cat:
    def bark(self):
        print("Meow!")

my_cat = Cat()
my_cat.bark() # Output: Meow

Encapsulation

  • Encapsulation bundles data (attributes) and methods operating on that data within a class.
  • Access to data is controlled via methods within the class, effectively hiding internal implementation details.

Getting and Setting Attributes

  • Methods are used to control attribute access and validation.

Abstraction

  • Abstraction simplifies complex systems by hiding internal details and presenting essential information to the user.
  • Classes and objects facilitate this abstraction layer.

Python's built-in data structures and OOP

  • Python's built-in structures (lists, dictionaries, tuples) are classes.
  • Their methods and attributes can be leveraged.
  • OOP enhances using and creating custom classes based on data structures.

Advantages of OOP in Python

  • Modularity: Code organized into classes and objects promotes reusability.
  • Reusability: Classes are reused within a program or across projects.
  • Maintainability: Changes in one part seldom affect other parts.
  • Readability: Well-structured code is more easily understood.
  • Scalability: Handling complex projects is often made easier through OOP.

Access Modifiers (Optional Advanced Topic)

  • Python lacks strict access modifiers (like public, private, protected).
  • Conventions are used:
    • Attributes and methods with a double underscore prefix (__) are considered “private”.
    • Attributes with a single leading underscore (_) are often treated as subject to change; a clue they're not part of the public interface.
  • These are primarily conventions rather than strict language rules.

Exception Handling (in OOP context)

  • Exception handling within OOP allows managing errors specifically within class methods or functions.
  • This approach helps handle potential issues within objects' operations.

Iterators and Generators (optional, more advanced)

  • Iterators and generators, while not strictly OOP constructs, can be utilized within OOP.
  • OOP principles can be applied for designing classes that manage iterations.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Description

تتناول هذه الدورة مقدمة شاملة في البرمجة الكائنية في لغة بايثون. تركز على تعريف الفئات وإنشاء الكائنات، مما يمكّن من كتابة كود منظم وقابل لإعادة الاستخدام.

More Like This

Python Programming Quiz
16 questions

Python Programming Quiz

ExtraordinaryJasper4112 avatar
ExtraordinaryJasper4112
Python Fundamentals
11 questions
Use Quizgecko on...
Browser
Browser