Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 자바편
- network configuration
- iterator
- /etc/network/interfaces
- 자료구조와 함께 배우는 알고리즘 입문
- resttemplate
- GIT
- 서버설정
- 리눅스
- 목록처리
- 데비안
- ㅒ
- d
- 알파회계
- 티스토리 쿠키 삭제
- 구멍가게코딩단
- 네트워크 설정
- Kernighan의 C언어 프로그래밍
- 이터레이터
- baeldung
- 페이징
- 선형대수
- 코드로배우는스프링부트웹프로젝트
- 처음 만나는 AI 수학 with Python
- 친절한SQL튜닝
- 자료구조와함께배우는알고리즘입문
- 스프링 시큐리티
- 코드로배우는스프링웹프로젝트
- 처음 만나는 AI수학 with Python
- 스프링부트핵심가이드
Archives
- Today
- Total
bright jazz music
Go - Account + NewAccount 캡술화/ func를 이용한 초기화 본문
캡슐화
package accounts
//Account struct
type Account struct {
owner string
balance int
}
//NewAccount creates Account
func NewAccount(owner string) *Account {
account := Account{owner: owner, balance: 0}
return &account //사본 말고 메모리 주소 반환
}
메인
package main
import (
"fmt"
"github.com/hojuncha997/learngo/accounts"
)
func main() {
account := accounts.NewAccount("hojun")
fmt.Println(account)
}
===
&{hojun 0} //사본이 아니라 그 객체임. 주소값으로 나오지 않은 이유는
//반환타입이 *Account 였기 때문임
'Language > Go' 카테고리의 다른 글
| Go -map type에 메소드 추가하기(Search) (1) | 2021.02.19 |
|---|---|
| Go - 메소드2 (Go의 메소드 내부적 호출/ struct에 메소드 추가하기) (1) | 2021.02.18 |
| Go - method(기본사용법, 리시버, 에러처리 등, Withdraw) (0) | 2021.02.18 |
| Go - struct (0) | 2021.02.18 |
| Go -maps (1) | 2021.02.18 |
Comments
