الكلاسات (Classes) في Visual Basic
📘 درس Visual Basic - الكلاسات (Classes)
🔹 ما هي الكلاسات؟
الكلاس (Class) هو قالب (Template) يُستخدم لإنشاء الكائنات (Objects) في البرمجة الشيئية. يحتوي الكلاس على الخصائص (Properties) والأساليب (Methods) التي تصف سلوك الكائنات وبياناتها.
💡 لماذا نستخدم الكلاسات؟
لأنها تسمح بتنظيم الكود في وحدات واضحة، وتسهّل إعادة الاستخدام والصيانة، وتدعم مفاهيم البرمجة الشيئية مثل الوراثة والتغليف.
✅ كيفية تعريف كلاس في Visual Basic
يمكنك تعريف كلاس باستخدام الكلمة المفتاحية Class
ثم كتابة الخصائص والأساليب بداخله.
💻 مثال مبسط على تعريف كلاس واستخدامه
Public Class Car
Public Property Model As String
Public Property Year As Integer
Public Sub DisplayInfo()
Console.WriteLine("الموديل: " & Model & ", السنة: " & Year)
End Sub
End Class
Module Program
Sub Main()
Dim myCar As New Car()
myCar.Model = "Honda Civic"
myCar.Year = 2020
myCar.DisplayInfo()
End Sub
End Module
🌍 English Explanation
A class is a template used to create objects in object-oriented programming. A class contains properties and methods that describe the behavior and data of objects.
💡 Why Use Classes?
Because they allow you to organize code into clear units, make it easier to reuse and maintain, and support OOP concepts like inheritance and encapsulation.
✅ How to Define a Class in Visual Basic
You can define a class using the Class
keyword and write the properties and methods inside it.
💻 Simple Example of Defining and Using a Class
Public Class Car
Public Property Model As String
Public Property Year As Integer
Public Sub DisplayInfo()
Console.WriteLine("Model: " & Model & ", Year: " & Year)
End Sub
End Class
Module Program
Sub Main()
Dim myCar As New Car()
myCar.Model = "Honda Civic"
myCar.Year = 2020
myCar.DisplayInfo()
End Sub
End Module
تعليقات
إرسال تعليق