Исходники и презентации

This commit is contained in:
2025-05-23 07:26:39 +03:00
parent aa948179d5
commit 02d8430a3a
514 changed files with 13773 additions and 0 deletions

View File

@ -0,0 +1,50 @@
package main
type Option func(*User)
func WithEmail(email string) Option {
return func(user *User) {
user.Email = email
}
}
func WithPhone(phone string) Option {
return func(user *User) {
user.Phone = phone
}
}
func WithAddress(address string) Option {
return func(user *User) {
user.Address = address
}
}
type User struct {
Name string
Surname string
Email string
Phone string
Address string
}
func NewUser(name string, surname string, options ...Option) User {
user := User{
Name: name,
Surname: surname,
}
for _, option := range options {
option(&user)
}
return user
}
func main() {
user1 := NewUser("Ivan", "Ivanov", WithEmail("ivanov@yandex.ru"))
user2 := NewUser("Petr", "Petrov", WithEmail("petrov@yandex.ru"), WithPhone("+67453"))
_ = user1
_ = user2
}