Why does delegation performed in Python?



Why does delegation performed in Python?..

Answer / chaitanya

Delegation is a technique that is used in object oriented programming. This is used to show the object and the behavior of the methods that are used. The class can be created to provide an implementation of the method that allows the method to be referenced. The delegate is having the parameter and the return value in an object. It also allows the methods to be passed as parameters and allow the defining of the callback methods that can be grouped together in multiple methods. These methods can be called from a single event. The example shows a class that captures the behavior of the file and converts data from lower to uppercase.

class upcase:

def __init__(self, out):

self._out = out

def write(self, s):

self._outfile.write(s.upper())

def __getattr__(self, name):

return getattr(self._out, name)

The write() method that is used in the upcase class converts the string to the uppercase before calling another method. The delegation is being given using the self.__outfile object.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Why cannot lambda forms in Python contain statements?

0 Answers  


How to send a object and its value to the garbage collection?

0 Answers  


What is the use of negative indices?

0 Answers  


What is python? State some programming language features of python.

0 Answers  


Name the function which helps to change the files permission

0 Answers  






What does len() do?

0 Answers  


Can python be used for web client and web server side programming?

0 Answers  


What are tokens in python?

0 Answers  


How the string does get converted to a number?

1 Answers  


Is numpy faster than pandas?

0 Answers  


What are supporting python packages for data science operations?

0 Answers  


How do you invoke the python interpreter for interactive use?

0 Answers  


Categories