首页 > 编程语言 > 详细

Python 抽象工厂方法

时间:2014-05-21 12:24:58      阅读:510      评论:0      收藏:0      [点我收藏+]

有没有好的python UML建模工具?求推荐,除eclipse的插件(因为不喜欢用eclipse)。pyNsource用的不是很好,pyUt不全。有没StarUML上的python插件?


bubuko.com,布布扣


import abc

class AbstractEnemyFactory( object ):
	__metaclass__ = abc.ABCMeta

	@abc.abstractmethod
	def createNinja( self ):
		pass

	@abc.abstractmethod
	def createSwordsman( self ):
		pass


class LowLevelEnemyFactory( AbstractEnemyFactory ):

	def createNinja( self ):
		return LowLevelEnemyNinja()

	def createSwordsman( self ):
		return LowLevelEnemySwordsman()


class HighLevelEnemyFactory( AbstractEnemyFactory ):

	def createNinja( self ):
		return HighLevelEnemyNinja()

	def createSwordsman( self ):
		return HighLevelEnemySwordsman()


class EnemyNinja( object ):

	__metaclass__ = abc.ABCMeta

	@abc.abstractmethod
	def ninjutsu_attack( self ):
		pass


class LowLevelEnemyNinja( EnemyNinja ):

	def __init__( self ):
		self._name = 'LowLevelEnemyNinja'
		self._chakra = 100
		self._attack_power = 5
		self._speed = 10

	def ninjutsu_attack( self ):
		print 'Ninja use ninjutsu.'
		print '[%s]: my chakra is %s and the power of attack is %s'			%( self._name, self._chakra, self._attack_power )


class HighLevelEnemyNinja( EnemyNinja ):

	def __init__( self ):
		self._name = 'EnemyNinja'
		self._chakra = 300
		self._attack_power = 15
		self._speed = 20

	def ninjutsu_attack( self ):
		print 'Ninja use ninjutsu.'
		print '[%s]: my chakra is %s and the power of attack is %s'			%( self._name, self._chakra, self._attack_power )

	def special_effect( self ):
		print '[%s]: special effect!'%( self._name )


class EnemySwordsman( object ):
	
	__metaclass__ = abc.ABCMeta

	@abc.abstractmethod
	def swords_attack( self ):
		pass


class LowLevelEnemySwordsman( EnemySwordsman ):

	def __init__( self ):
		self._name = 'LowLevelEnemySwordsman'
		self._blood = 100
		self._attack_power = 5
		self._speed = 10



	def swords_attack( self ):
		print 'Swordsman use swords.'
		print '[%s]: my blood is %s and the power of attack is %s'			%( self._name, self._blood, self._attack_power )
	


class HighLevelEnemySwordsman( EnemySwordsman ):

	def __init__( self ):
		self._name = 'HighLevelEnemySwordsman'
		self._blood = 300
		self._attack_power = 30
		self._speed = 30

	def swords_attack( self ):
		print 'Swordsman use swords.'
		print '[%s]: my blood is %s and the power of attack is %s'			%( self._name, self._blood, self._attack_power )

	def special_effect( self ):
		print '[%s]: special effect!'


if __name__ == '__main__':

	h = HighLevelEnemyFactory()
	h.createNinja().ninjutsu_attack()
	h.createNinja().special_effect()
	h.createSwordsman().swords_attack()


Python 抽象工厂方法,布布扣,bubuko.com

Python 抽象工厂方法

原文:http://blog.csdn.net/pandora_madara/article/details/26450219

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!