Rexx প্রোগ্রামিং ভাষায়, Methods এবং Attributes এর ধারণা সাধারণত অবজেক্ট-ওরিয়েন্টেড প্রোগ্রামিং (OOP) এর সাথে সম্পর্কিত। Rexx-এ অবজেক্ট-ওরিয়েন্টেড প্রোগ্রামিং সাপোর্ট করে, এবং এর মাধ্যমে আপনি অবজেক্ট তৈরি করতে পারেন যার মধ্যে Attributes (গুণাবলী) এবং Methods (পদ্ধতি) থাকতে পারে।
- Attributes হলো অবজেক্টের গুণাবলী বা বৈশিষ্ট্য, যা অবজেক্টের তথ্য ধারণ করে।
- Methods হলো অবজেক্টের ওপর সম্পাদনাযোগ্য কার্যক্রম, যা অবজেক্টের উপর কোনো অপারেশন চালায়।
Rexx-এ OOP এর ধারণাকে সমর্থন করে, আপনি একটি ক্লাস তৈরি করে তার মধ্যে বিভিন্ন গুণাবলী (attributes) এবং পদ্ধতি (methods) ব্যবহার করতে পারেন।
১. Attributes (গুণাবলী)
Attributes হল অবজেক্টের বৈশিষ্ট্য বা ডেটা। এই ডেটাগুলি অবজেক্টের অংশ হিসেবে সংরক্ষিত থাকে এবং আপনি এগুলির মান পরিবর্তন করতে পারেন।
Attribute এর উদাহরণ:
/* Class defining an object with attributes */
class person
person.name = "" /* Attribute for name */
person.age = 0 /* Attribute for age */
return
/* Create object and set attributes */
john = person~new()
john.name = "John Doe"
john.age = 30
say "Name: " john.name
say "Age: " john.ageব্যাখ্যা:
- এখানে
personক্লাসে দুটি attribute:nameএবংageরয়েছে। johnনামের একটি অবজেক্ট তৈরি করা হয়েছে এবংnameএবংageএর মান সেট করা হয়েছে।
২. Methods (পদ্ধতি)
Methods হলো ফাংশন বা সাবরুটিন যা ক্লাসের মধ্যে অবজেক্টের উপরে কার্যক্রম পরিচালনা করতে ব্যবহৃত হয়। এটি অবজেক্টের attribute বা গুণাবলী পরিবর্তন করতে পারে অথবা অন্যান্য কাজ সম্পাদন করতে পারে।
Method এর উদাহরণ:
/* Class defining an object with attributes and method */
class person
person.name = "" /* Attribute for name */
person.age = 0 /* Attribute for age */
/* Method to print details of the person */
person.printDetails: procedure
say "Name: " person.name
say "Age: " person.age
return
return
/* Create object and set attributes */
john = person~new()
john.name = "John Doe"
john.age = 30
/* Call method of the object */
john~printDetails()ব্যাখ্যা:
- এখানে
personক্লাসের মধ্যে একটি methodprintDetailsতৈরি করা হয়েছে, যাnameএবংageattribute প্রদর্শন করবে। john~printDetails()কল করার মাধ্যমে অবজেক্টের attribute গুলি প্রদর্শিত হয়।
৩. Method এবং Attribute Access
Rexx-এ অবজেক্টের attribute এবং method অ্যাক্সেস করার জন্য কিছু বিশেষ সিম্বল ব্যবহার করা হয়:
.(ডট): এটা একটি attribute বা গুণাবলী অ্যাক্সেস করার জন্য ব্যবহৃত হয়।~(টিলড): এটা একটি method কল করার জন্য ব্যবহৃত হয়।
Method এবং Attribute Access এর উদাহরণ:
/* Class with methods and attributes */
class car
car.model = "" /* Attribute for model */
car.year = 0 /* Attribute for year */
car.printDetails: procedure
say "Car Model: " car.model
say "Year: " car.year
return
return
/* Create an object */
myCar = car~new()
myCar.model = "Tesla Model S"
myCar.year = 2022
/* Accessing attributes and calling method */
say "Model: " myCar.model
myCar~printDetails()ব্যাখ্যা:
myCar.modelদ্বারাmodelattribute অ্যাক্সেস করা হয়েছে।myCar~printDetails()দ্বারাprintDetailsmethod কল করা হয়েছে।
৪. Object Creation and Initialization (অবজেক্ট তৈরি এবং ইনিশিয়ালাইজেশন)
Rexx-এ অবজেক্ট তৈরি করতে একটি ক্লাসের new() method ব্যবহার করা হয়। এটা একটি নতুন অবজেক্ট তৈরি করে এবং তার attributes এর মান সেট করতে সাহায্য করে।
Object Creation and Initialization উদাহরণ:
/* Class with attributes and method */
class student
student.name = ""
student.rollNo = 0
/* Method to display student details */
student.display: procedure
say "Name: " student.name
say "Roll No: " student.rollNo
return
return
/* Create an object and initialize attributes */
s1 = student~new()
s1.name = "Alice"
s1.rollNo = 101
/* Call method */
s1~display()ব্যাখ্যা:
student~new()দিয়ে নতুনstudentঅবজেক্ট তৈরি করা হয়।- তারপর
nameএবংrollNoattributes এ মান দেওয়া হয় এবংdisplaymethod দিয়ে ডেটা প্রদর্শিত হয়।
সারাংশ:
- Attributes হল অবজেক্টের গুণাবলী বা ডেটা, যা অবজেক্টের সাথে সম্পর্কিত থাকে এবং এটি অবজেক্টের বর্তমান অবস্থা নির্ধারণ করে।
- Methods হল অবজেক্টের ওপর কার্যক্রম পরিচালনা করার জন্য ব্যবহৃত ফাংশন বা সাবরুটিন।
- Rexx-এ
.(ডট) দিয়ে attribute অ্যাক্সেস করা হয় এবং~(টিলড) দিয়ে method কল করা হয়।
Rexx-এর মাধ্যমে OOP ব্যবহার করে আপনাকে শক্তিশালী এবং পুনঃব্যবহারযোগ্য কোড লেখার সুযোগ পাওয়া যায়।
Read more