prototoype1 golang design pattern #3 Prototype Prototype 패턴은 매번 객체를 새로 생성하기보다는 original 객체를 복사해서 필요한 부분만 수정해서 사용하는 패턴입니다. 1 2 3 4 5 6 7 8 9 type Address struct { City string Postcode string } type Person struct { Name string Address *Address } cs 위 같이 구조체가 정의되어 있다고 가정해봅시다. 1 2 3 4 5 6 7 alex := Person{ "alex", &Address{"Seoul", "14321"}, } sarah := alex sarah.Address.City = "Busan" cs 위처럼 코드를 작성하게 되면 Address가 포인터 타입이기 때문에 alex의 주소도 Busan으로 바.. 2021. 11. 11. 이전 1 다음