Marlysson / Algoritmos-Redes

Implementação dos algoritmos de Hamming e CRC na camadas de correção/detecção de erros
2 stars 0 forks source link

To add method by delegation and using hamming by composition #2

Open Marlysson opened 8 years ago

Marlysson commented 8 years ago

Using a method by composition in Frame object and using by delegation.

class Frame:
    def __init___(self):
        self.validator = Hamming("pair")

    def check(self):
        return self.validator(self)
frame = Frame("0101")

if frame.check():
    print("It's valid")
else:
    print("Invalid")

Which choice?

hamming.check(frame)
frame.check()

USE OF STRATEGY PATTERN