Demo entry 6776223

Adapter

   

Submitted by anonymous on Nov 30, 2018 at 12:35
Language: Python. Code size: 766 Bytes.

class Elf:
    name = 'Rosalor'

    def le_suilon(self):
        print('Elf {name} says: Greeting'.format(name=self.name))


class Orc:
    name = 'Khadgar'

    def mok_rah(self):
        print('Orc {name} says: Greeting'.format(name=self.name))


class Human:
    name = 'Severus Smithy'

    def say_hello(self):
        print('Human {name} says: Greeting'.format(name=self.name))


heroes = [
    Elf(),
    Orc(),
    Human()
]


if __name__ == '__main__':
    heroes = [
        Elf(),
        Orc(),
        Human()
    ]

    for hero in heroes:
        if isinstance(hero, Elf):
            hero.le_suilon()
        elif isinstance(hero, Orc):
            hero.mok_rah()
        else:
            hero.say_hello()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).