종우의 컴퓨터 공간
Go 커스텀 타입 (Go Custom Type) 본문
Go is not a OOP language like Java or Python. To use it as an OOP language, we can use this design pattern of what is called custom type. Custom type can be created by using one of the existing primitive data types such as string, integer, or slice. It is possible to use receiver function to add functionality to it which only can be accessible through using it.
(고는 자바나 파이썬처럼 객체지향 언어가 아니다. 하지만 커스텀 타입이라는 디자인 패턴을 사용함으로서 어느정도 객체지향의 특성을 따라할 수 있다. 커스텀 타입은 문자열, 정수, 혹은 배열(슬라이스)과 같은 기본적으로 제공되는 데이터 타입을 기반으로 만들 수 있다. 직접 만든 커스텀 타입에 리시버 함수를 추가함으로서 그 커스텀 타입에 한정해서 함수를 부를 수도 있다.)
1. 'deck' type has been created based on slice of string
2. 'print' function is a receiver function
(1. 'deck' 타입은 슬라이스를 기반으로 만들어진 커스텀 타입이다.
2. 'print; 함수는 리시버 함수이다.)
'고 언어 (Go Lang)' 카테고리의 다른 글
Go 자료구조 (Go data structure) (0) | 2021.12.15 |
---|---|
Go 패키지와 import (Go package, import) (0) | 2021.12.15 |
Go 커맨드라인 (GO CLI) (0) | 2021.12.15 |