Initial commit with methods module

This commit is contained in:
Fabio Scotto di Santolo
2024-11-19 12:22:09 +01:00
parent cbe2ed118f
commit ecb4ea20a8
8 changed files with 65 additions and 2 deletions

14
methods/models/person.go Normal file
View File

@@ -0,0 +1,14 @@
package models
import "fmt"
type Person struct {
Name string
LastName string
Age int
}
// Presentation - Greet everyone and show up
func (p Person) Presentation() string {
return fmt.Sprintf("Hi, everyone! I'm %s %s and I have %d years old.\n", p.Name, p.LastName, p.Age)
}

View File

@@ -0,0 +1,5 @@
package models
type Presenter interface {
Presentation() string
}

13
methods/models/student.go Normal file
View File

@@ -0,0 +1,13 @@
package models
import "fmt"
type Student struct {
Person
Class string
}
// Presentation - Greet the teacher and show up
func (s Student) Presentation() string {
return fmt.Sprintf("Good morning teacher, I'm %s %s.\n", s.Person.Name, s.Person.LastName)
}