Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Why does delegation performed in Python?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the sleeping time of python?

805


How do you reload a python module?

960


Why do we use __ init __ in python?

853


How many constructors can a class have?

907


What are disadvantages of python?

897


What is enumerate() function in python?

891


How are arguments passed - by reference or by value?

795


Write an example of a print function in python?

807


How does ternary operator work in python?

928


What is anonymous function or lambda function?

823


How to write a text from from another text file in python ?

898


How do I run a python file in python shell?

826


Are sets hashable python?

813


How to remove items from a list while iterating?

739


What is list in python?

860