Demo entry 6776225

Adapter1

   

Submitted by anonymous on Nov 30, 2018 at 12:39
Language: Python. Code size: 1.0 kB.

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))


class ElfAdapter:
    def __init__(self, elf):
        self.elf = elf

    def call_me(self):
        self.elf.le_suilon()


class OrcAdapter:
    def __init__(self, orc):
        self.orc = orc

    def call_me(self):
        self.orc.mok_rah()


class HumanAdapter:
    def __init__(self, human):
        self.human = human

    def call_me(self):
        self.human.say_hello()


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

    for hero in heroes:
        hero.call_me()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).