Defining and implementing interfaces In Hindi

Defining and implementing interfaces In Hindi

पीएचपी प्रोग्रामिंग में एक इंटरफ़ेस यूजर डिफाइन क्लास पैरामीटर, मेथड, और रिटर्न डाटा टाइप कन्सेप्ट का कॉम्बिनेशन होता है, जो प्रोग्रामर को कुछ कस्टम स्टेप्स में एक क्लास सेट को डिफाइन करने में हेल्प करता है. जिसमे एक कस्टम क्लास ऑब्जेक्ट को अप्लाई करना होता है, जो बिना किसी प्रॉपर मेथड के साथ इम्प्लीमेंटेशन में दिए गए है। कस्टम क्लास में इंटरफ़ेस कांसेप्ट पॉलीमॉर्फिज्म फीचर्स को इनेबल करते हैं. जहाँ प्रोग्राम में मल्टीप्ल कस्टम क्लास एक ही इंटरफ़ेस को अडॉप्ट कर सकती हैं. जिससे कि ये फ्लेक्सिबिलिटी मेन्टेन करते हुए किसी क्लास को स्पेशल इंटरफ़ेस फीचर्स और कैपेबिलिटी प्रोवाइड करते है।

Defining and implementing interfaces In Hindi

What is an Interface in PHP Programming?

पीएचपी प्रोग्राम में एक इंटरफ़ेस क्लास यूजर डिफाइन मेथड या सिग्नेचरहोती है, जिसमे क्लास मेथड का नाम, क्लास पैरामीटर, और रिटर्न डाटा टाइप की एक कस्टम यूजर डिफाइन लिस्ट को डिफाइन करता है. जो की एक इंटरफ़ेस को अप्लाई करके किसी भी क्लास के माध्यम से इम्प्लीमेंट किया जाना चाहिए। जैसे की, एक कस्टम क्लास इंटरफ़ेस में उन स्टेप्स के लिए कोई इम्प्लीमेंटेशन प्रोवाइड नहीं करता है।

Key points of an interface in PHP programming.

  • किसी यूजर डिफाइन क्लास में एक इंटरफ़ेस में केवल क्लास डिक्लेअर मेथड सिग्नेचर होते हैं।
  • क्लास प्रोग्राम में एक क्लास जो एक कस्टम क्लास इंटरफ़ेस को अप्लाई करती है, उसे उस क्लास में डिफाइन इंटरफ़ेस में डिफाइन किए गए सभी मेथड टाइप को अप्लाई करना होगा।
  • यूजर डिफाइन एक क्लास कई यूजर क्रिएटेड इंटरफ़ेस को अप्लाई कर सकती है।
  • याद रहे, एक क्लास इंटरफ़ेस में प्रॉपर्टी या मेथड इम्प्लीमेंटेशन नहीं हो सकते है।

Defining a Class Interface in PHP Programming.

किसी यूजर डिफाइन क्लास में एक इंटरफ़ेस को इंटरफ़ेस कीवर्ड को यूज़ करके क्रिएट या डिफाइन किया जाता है, इसके बाद क्लास में क्रिएटेड क्लास इंटरफ़ेस का नाम और मेथड सिग्नेचर डिफाइन या क्रिएट किए जाते हैं।

Syntax for defining an interface in a PHP program.

interface InterfaceName {

    public function methodName();  // define class Method signature

    public function nextMethod($parameter);  // declare next method signature in class

}

Implementing an interface in PHP programming.

किसी क्लास प्रोग्राम में एक यूजर डिफाइन इंटरफ़ेस को अप्लाई करने के लिए एक क्लास में इम्प्लीमेंट्स कीवर्ड को अप्लाई करना होगा। इसके बाद यूजर क्रिएटेड कस्टम क्लास में इंटरफ़ेस मेथड में डिफाइन किए गए हर क्लास मेथड के लिए एक सॉलिड इम्प्लीमेंटेशन देना होगा।

Syntax for implementing a custom interface in a class.

class ProgramClassName implements InterfaceName {

    // Let define and Implementing the class methods defined in the class interface

    public function methodName() {

        // here class Method implementation

    }

    public function nextMethod($parameter) {

        // here next class Method implementation

    }

}

Important notes about interfaces.

  • यूजर डिफाइन क्लास में स्टेप्स का नाम, क्लास पैरामीटर, और क्लास विजिबिलिटी सामान्यता पब्लिक क्लास इंटरफ़ेस के बराबर होनी चाहिए।
  • किसी यूजर डिफाइन क्लास में इन्हे कॉमा ऑपरेटर से सेपरेट करके कई इंटरफ़ेस को अप्लाई किया जा सकता है।

Example of defining and implementing a class interface in PHP programming.

Define or create an interface in a user-defined class.

<?php

// here we Implement the object interface in a class

class Circle implements object {

    private $radius;

    // here Constructor to initialize the radius

    public function __construct($radius) {

        $this->radius = $radius;

    }

    // here we Implementing the area class method

    public function area() {

        return pi() * $this->radius * $this->radius;

    }

    // here we Implementing the parameter class method

    public function parameter() {

        return 2 * pi() * $this->radius;

    }

}

// here we Create an object of the Circle class

$circle = new Circle(2);

// Display the area and parameter

echo “Display the Area of circle – ” . $circle->area() . “\n”; 

echo “Display parameter of circle – ” . $circle->parameter() . “\n”;

?>

Implementing a class interface explanation.

  • इस प्रोग्राम में हमने एक object नाम का एक क्लास इंटरफ़ेस क्रिएट किया है, इसमें दो कस्टम क्लास मेथड सिग्नेचर हैं. जैसे, area() और parameter() फंक्शन है.
  • यहाँ Circle क्लास object इंटरफ़ेस को इम्प्लीमेंट करती है, और area() और parameter() मेथड के लिए सॉलिड इम्प्लीमेंटेशन प्रोवाइड करती है।
  • यहाँ Circle क्लास में ऑब्जेक्ट क्रिएट करते समय दिए गए रेडियस के आधार पर सर्कल एरिया और पैरामीटर को कैलकुलेट करती है।

Implementing Multiple Interfaces in a Class.

एक यूजर डिफाइन क्लास में कई इंटरफ़ेस अप्लाई किए जा सकते है। इस कंडीशन में, यहाँ यूजर डिफाइन क्लास को हर इंडिविजुअल क्लास इंटरफ़ेस में डिफाइन या क्रिएट किए गए सभी क्लास मेथड के लिए इम्प्लीमेंशन को प्रोवाइड करना होगा।

Example of multiple interfaces in a user-defined class.

<?php

// here we Define or create first class interface

interface design {

    public function area();

    public function parameter();

}

// here we Define or create second class interface

interface sketchable {

    public function sketch();

}

// here we Implement both first and second class interfaces in a class

class Rectangle implements design, sketchable {

    private $height;

    private $width;

    // here the class Constructor to initialize design dimensions

    public function __construct($height, $width) {

        $this->height = $height;

        $this->width = $width;

    }

    // here we Implement the area method from design class interface

    public function area() {

        return $this->height * $this->width;

    }

    // here we Implement parameter method from design class interface

    public function parameter() {

        return 2 * ($this->height  + $this->width);

    }

    // here we Implement sketch method from sketchable interface

    public function sketch() {

        echo “Sketching a rectangle design \n “;

    }

}

// here we Create an object of the Rectangle class

$rectangle = new Rectangle(3, 3);

echo “Display Area of rectangle – ” . $rectangle->area() . “\n”;  // Result – Display Area of rectangle – 9

echo “Display parameter of rectangle – ” . $rectangle->parameter() . “\n”;  // Result – Display parameter of rectangle – 12

$rectangle->sketch();  // Result – Sketching a rectangle design

?>

Explanation of Implementing Multiple Interfaces.

  • यहाँ इस क्लास प्रोग्राम में Rectangle क्लास Design और sketchable दोनों कस्टम क्लास इंटरफ़ेस को अप्लाई करती है।
  • जिसमे की Rectangle क्लास Design और sketchable दोनों इंटरफ़ेस द्वारा जरूरी सभी स्टेप्स के लिए इम्प्लीमेंटेशन प्रोवाइड करती है. जैसे, area(), parameter(), और draw() फंक्शन है.

Leave a Reply