Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cc3a46d

Browse files
author
mostafa
committed
struct as class
1 parent b87a337 commit cc3a46d

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* [map](https://github.com/code4mk/golang-basic/tree/main/map)
99
* [function](https://github.com/code4mk/golang-basic/tree/main/function)
1010
* [method](https://github.com/code4mk/golang-basic/tree/main/method)
11-
* [pointer](https://github.com/code4mk/golang-basic/tree/main/ponter)
11+
* [pointer](https://github.com/code4mk/golang-basic/tree/main/pointer)
1212
* [struct](https://github.com/code4mk/golang-basic/tree/main/struct)
1313
* [oop (inheritance,interface,polymorphism)](https://github.com/code4mk/golang-basic/tree/main/oop)
1414

‎oop/struct-class/employee/employee.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package employee
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
type Employee struct {
8+
FirstName string
9+
Age int
10+
Phone string
11+
}
12+
13+
func New(FirstName string, Age int, Phone string) Employee {
14+
e := Employee{
15+
FirstName, Age, Phone,
16+
}
17+
return e
18+
}
19+
20+
func (e Employee) Info() {
21+
fmt.Println(e)
22+
}

‎oop/struct-class/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module oop
2+
3+
go 1.16

‎oop/struct-class/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import "oop/employee"
4+
5+
func main() {
6+
e := employee.Employee{
7+
FirstName: "Sam",
8+
Age: 21,
9+
Phone: "01751255157",
10+
}
11+
e.Info()
12+
13+
// var p employee.Employee
14+
// p.Info()
15+
16+
// constructor
17+
var q = employee.New("kamal", 21, "01851255158")
18+
q.Info()
19+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /