Advertisements
Advertisements
प्रश्न
Differentiate between the pure method and Impure method.
फरक स्पष्ट करा
Advertisements
उत्तर
| Feature | Pure Method | Impure Method |
| State Modification | Does not modify the original state of the object or any external data. | Modifies the state of the object, instance variables, or global variables. |
| Side Effects | Has zero side effects (no changes to files, console output, or database records). | Has side effects because it changes data variables or prints output to the environment. |
| Output Consistency | Always returns the exact same output if given the exact same input arguments. | May return different outputs for the same inputs if internal or external states change. |
| Passing Mechanism | Typically relies on call by value using primitive data variables. | Typically relies on call by reference using object references or arrays. |
| Common Use Case | Case is used for mathematical operations, sorting arrays safely, or checking boolean conditions. |
Used for updating an object's profile, saving records, or tracking incrementing IDs. |
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
