Demo entry 2135450

adapter

   

Submitted by Fernando Taglapietra on Jul 08, 2015 at 22:49
Language: Python. Code size: 1.1 kB.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

class Playstation(object):

	def __init__(self):
		self.name = "Playstation"
	
	def runBluRay(self):
		return "jogar The Last of US..."

class Xbox(object):

	def __init__(self):
		self.name = "Xbox"

	def runDvD(self):
		return "jogar Halo..."

class Nintendo(object):
	
	def __init__(self):
		self.name= "Nintendo"
	
	def runBdRom(self):
		return "jogar Mario..."
			
class PC(object):

	def __init__(self):
		self.name="PC"

	def runSteam(self, versao):
		return "jogar Dota %s" % (versao)
			
class Adapter(object):

	def __init__(self, obj, **metodos):
		self.obj = obj
		self.__dict__.update(metodos)
	
	def __getattr__(self, attr):
		return getattr(self.obj, attr)		
		
objetos = []

pc		= PC()
pla		= Playstation()
ntd		= Nintendo()
xbox	= Xbox()

objetos.append( Adapter(pla, play= pla.runBluRay ))
objetos.append( Adapter(ntd, play= ntd.runBdRom ))
objetos.append( Adapter(xbox, play= xbox.runDvD ))
objetos.append( Adapter(pc,  play=lambda:  pc.runSteam(2)) )

for obj in objetos:
	print "%s  GAME:  %s " % (obj.name, obj.play())

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).