diff --git a/exercise-1.py b/exercise-1.py index 1323c1b..a65d8cb 100644 --- a/exercise-1.py +++ b/exercise-1.py @@ -1,5 +1,3 @@ -# encoding: utf-8 - """ Single Responsibility Principle to jedna z zasad SOLID. Mówi ona, że każda klasa powinna mieć tylko jeden obszar odpowiedzialności i tylko jeden powód do zmiany. @@ -15,18 +13,23 @@ import unittest -EMAIL_PATTERN = re.compile(r'^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$') -class Person: +class Email(object): + def __init__(self, email): + EMAIL_PATTERN = re.compile(r'^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$') + if not EMAIL_PATTERN.match(email): + raise ValueError('Invalid email') + else: + self.email = email + +class Person(Email): def __init__(self, first_name, last_name, email): assert isinstance(first_name, str) assert isinstance(last_name, str) assert isinstance(email, str) - - self.first_name = first_name + + self.first_name = first_name self.last_name = last_name - if EMAIL_PATTERN.match(email) is None: - raise ValueError('Invalid email') - else: - self.email = email + super(Person, self).__init__(email) +