Twoim zadaniem jest napisanie klasy Customer
w języku Python, która będzie reprezentować dane klienta.
-
prywatne pole
name
(typ: string): przechowuje imię klienta -
prywatne pole
email
(typ: string): przechowuje adres email klienta
-
__init__(self, name: str, email: str)
: konstruktor, który inicjalizuje obiekt klasyCustomer
przyjmując wartości dlaname
(imię klienta) iemail
(adres email klienta). -
name(self) -> str
: getter zwracający wartość_name
. -
name(self, value: str) -> None
: setter ustawiający wartość_name
na podstawie podanej wartościvalue
. Jeśli wartośćvalue
jest pusta, powinien zostać zgłoszony wyjątekValueError
z komunikatem "Name cannot be empty". -
email(self) -> str
: getter zwracający wartość_email
. -
email(self, value: str) -> None
: setter ustawiający wartość_email
na podstawie podanej wartościvalue
. Jeśli wartośćvalue
nie jest poprawnym adresem email, powinien zostać zgłoszony wyjątekValueError
z komunikatem "Invalid email format". -
validate_email(self, email: str) -> bool
: metoda prywatna sprawdzająca poprawność formatu adresu email. -
save_to_database(self) -> None
: metoda zapisująca dane klienta (na potrzeby zadania wystarczy do do csv).
customer = Customer("John Doe", "[email protected]")
print(customer.name) # Output: John Doe
print(customer.email) # Output: [email protected]
customer.name = "Jane Smith"
customer.email = "[email protected]"
customer.save_to_database()