Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

05 oop #61

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .gitignore

This file was deleted.

201 changes: 0 additions & 201 deletions LICENSE

This file was deleted.

39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Golang united school - part 1

Inside of this repository you can find all homeworks for the first part of the [Golang united school](https://community-z.com/communities/golang/golang-united-school)

Practical assigment destributed acroos the branches `lecture-*`

We use platform [Autocode](https://autocode-next.lab.epam.com) to track the homework, please use it to complete tasks.

## How to use `Autocode`?
To use autocode you must be registered on the platform (please specify your real name).
After registration, please authorize the platform to use your `github` account, platform will automatically fork the repo to your account when you start task.

You might code in any IDEA or TextEditor for the development, to sumbit the code you just need to commit it to the specific branch, after that you will have an ability to submit code on the platform and get all test results.

Good Luck!
OOP, structs and interfaces
---
Working with structs!
We are to create User object
```go
type User struct {

}
```
- This struct **must** implement interface
```go
type UserInterface interface {
SetFirstName(string)
SetLastName(string)
FullName() string
}
```
- `user.FullName()` **must** return string with format "lastName firstName"
- lastName firstName must be unavailable to read/modify directly.
- `New()` constructor **must** be present for `User` struct
- Implement functions(not methods):
- `func ResetUser(input) ` accepts 1 param as input and resets both lastName and firstName (set to empty value)
- `func IsUser(input) bool ` accepts 1 param as input and return `true` is input is of type `User`
- `func ProcessUser(input) string` accepts 1 param as input of type `UserInterface`, sets last/first names and returns fullname
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module golang-united-school-homework-1

go 1.18
37 changes: 37 additions & 0 deletions s01.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package structs

import "fmt"

type User struct {
firstName string
lastName string
}

type UserInterface interface {
SetFirstName(string)
SetLastName(string)
FullName() string
}

func (u *User) SetFirstName(firstname string) {
u.firstName = firstname
}
func (u *User) SetLastName(lastname string) {
u.lastName = lastname
}
func (u *User) FullName() string {
return u.firstName + " " + u.lastName
}

func New() User {
return User{}
}
func ResetUser(user *User) {
user = &User{}
}
func IsUser(user interface{}) bool {
return fmt.Sprintf("%T\n", user) == fmt.Sprintf("%T\n", User{})
}
func ProcessUser(ui UserInterface) string {
return ui.FullName()
}