From befbc2dfe690fe70ff28ab88b3faf45fa4bad959 Mon Sep 17 00:00:00 2001 From: adamfake <39712155+adamfake@users.noreply.github.com> Date: Sat, 16 Jun 2018 12:33:38 +0200 Subject: [PATCH] Update exercise-1.py --- exercise-1.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) 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) +