전체 글
-
25장 - 공통 모듈을 추출해서 여러 플랫폼에서 재사용하라Kotlin/Effective Kotlin 요약 2023. 3. 8. 00:01
중복을 다루기 기업이 한 플랫폼만을 대상으로 애플리케이션을 만드는 경우는 없습니다. 이때 소스코드를 공유할 수 있다면 큰 이득이 발생할 수 있습니다. 풀스택 개발 코틀린의 굉장한 장점 중 하나는 코틀린이 자바스크립트로 컴파일될 수 있다는 것입니다. 예를 들어 리액트 프레임워크와 코틀린/JS를 함께 사용해서 웹 프런트엔드를 만들 수도 있습니다. 이때 공통 코드, API 엔드포인트 정의, 추상화 등을 재사용할 수 있습니다. 모바일 개발 안드로이드 전용으로 애플리케이션을 만드는 경우가 거의 없습니다. AOS/ IOS를 개별적으로 개발하곤 합니다. IOS의 경우 LLVM을 사용하여 네이티브 코드로 컴파일할 수 있는 코틀린/네이티브를 사용하면 Objective-C 프레임워크로 변환할 수 있습니다. 이렇게 변환하면..
-
24장 - 제네릭 타입과 variance 한정자를 활용하라Kotlin/Effective Kotlin 요약 2023. 3. 7. 00:01
불공변성(invariant)이란? 제네릭 타입으로 만들어지는 타입이 서로 관련성이 없다는 의미입니다. 예를 들어 다음 제네릭들은 서로 어떠한 관련성도 갖지 않습니다. - Cup - Cup - Cup - Cup 공변성(covariant)이란? 어떤 관련성을 원할 경우 out 또는 in이라는 variance 한정자를 붙일 수 있습니다. out은 타입 파라미터를 공변성으로 만듭니다. A가 B의 서브타입일때 Cup가 Cup의 서브타입이라는 의미입니다. in은 반대 의미입니다. 타입 파라미터를 contravariant(반변성)으로 만듭니다. A가 B의 서브타입일때 Cup가 Cup의 슈퍼타입이라는 의미입니다. 코틀린에서 함수와 variance 코틀린 함수 타입의 모든 파라미터 타입은 contravariant입니다...
-
23장 - 타입 파라미터의 섀도잉을 피하라Kotlin/Effective Kotlin 요약 2023. 3. 6. 00:01
섀도잉이란? 다음 코드처럼 지역 파라미터가 외부 스코프에 있는 프로퍼티를 가리키는 경우 섀도잉이라 부릅니다. class Forest(val name: Stirng){ fun addTree(name: String) { //... } } 이런 현상은 클래스 타입 파라미터와 함수 타입 파라미터 사이에서도 발생합니다. 특히 제너릭과 함께 사용되는 경우 다양한 문제가 발생합니다. interface Tree class Birch: Tree class Sqruce: Tree class Forest{ fun addTree(tree: T){ println("adding tree ...") } } fun main() { val forest = Forest() forest.addTree(Birch()) forest.addT..
-
22장 - 일반적인 알고리즘을 구현할 때 제너릭을 사용하라Kotlin/Effective Kotlin 요약 2023. 3. 5. 00:01
제네릭 함수 아규먼트로 함수에 값을 전달할 수 있는 것처럼, 타입 아규먼트를 사용하면 함수에 타입을 전달할 수 있습니다. 이를 제네릭 함수라고 합니다. 대표적으로는 filter 함수가 있으며 타입 파라미터로 T를 갖습니다. 이로 인해 컴파일러가 타입을 조금이라도 더 정확하게 추측할 수 있도록합니다. 또한 IDE도 이를 기반으로 여러 가지 유용한 제안을 해줍니다. 기본적으로 List Set 처럼 구체적인 타입으로 컬렉션을 만들 수 있게 클래스와 인터페이스에 도입된 기능입니다. 제네릭 제한 구체적인 타입의 서브타입만 사용하도록 제한할 수 있습니다. 콜론 뒤에 슈퍼 타입을 설정하여 제한을 거는 예시입니다. 예를 들어 T: Any를 활용하면 nullable이 아닌 모든 타입을 나타냅니다. 예를 들어 T: Ite..
-
Docker로 Nginx 정적 파일 서빙 & 리버스 프록시 설정MSA & 쿠버네티스(Kubernetes) - k8s 2023. 3. 4. 12:43
개요 도커가 설치되어 있다고 가정되고 진행됩니다. 도커에 대한 전반적인 지식이 조금 있다고 가정되고 진행됩니다. Docker Nginx 이미지 받기 docker pull nginx 정적파일 준비하기 echo "Hello, Local Index.html" >> index.html 파일이 저장된 경로 /Desktop/docker 볼륨 옵션 주어 nginx 이미지 컨테이너로 생성 docker run -d --name my_nginx -p 80:80 -v [your_computer_user_path]\Desktop\docker:/mycustome/path -it nginx 볼륨 기능을 통해 컨테이너와 독립하여 데이터를 관리할 수 있습니다. 컨테이너와 독립되는 호스트 PC(로컬 PC)의 저장공간에서 볼륨에 연결시..
-
21장 - 일반적인 프로퍼티 패턴은 프로퍼티 위임으로 만들어라Kotlin/Effective Kotlin 요약 2023. 3. 4. 00:01
프로퍼티 위임이란? property delegate를 사용하는 것을 프로퍼티 위임이라 부릅니다 대표적으로 지연 프로퍼티가 있습니다. lazy 프로퍼티는 이후에 처음 사용하는 요청이 들어올 때 초기화되는 프로퍼티를 의미합니다. 다른 언어에서는 대부분 이를 복잡하게 구현해야 하지만 코틀린에서는 lazy 함수를 활용하는 프로퍼티 위임으로 간단하게 구현할 수 있습니다. 또한 변화가 있을 때 이를 감지하는 observable 패턴을 쉽게 만들 수 있습니다. 예를 들어 목록을 출력하는 리스트 어댑터가 있다면 내부 데이터가 변경될 때마다 변경된 내용을 다시 출력해야 합니다. 이때 observable 델리게이트를 기반으로 간단하게 구현할 수 있습니다. 프로퍼티가 사용될 때 로그를 출력하는 예제 기본적인 구현 방법은 게..
-
9장 - 애플리케이션 조립하기클린 코드(Clean Code)/만들면서 배우는 클린 아키텍처 요약 2023. 3. 3. 00:01
조립을 신경 써야 하는 이유 코드 의존성을 모두 도메인 방향으로 향하기 위해서입니다. 설정 컴포넌트 모든 클래스에 대한 의존성을 가지는 설정 컴포넌트가 있어야 합니다. 이 클래스는 단일 책임 원칙을 위반하지만 애플리케이션의 나머지 부분을 깔끔하게 유지하기 위해서는 필요합니다. 스프링의 클래스패스 스캐닝으로 조립하기 스프링을 통해 애플리케이션을 조립한 결과물을 application context라고 합니다. 애플리케이션 컨텍스트는 애플리케이션을 구성하는 모든 객체(bean)를 포함합니다. 스프링은 @Component가 붙은 클래스를 찾아 객체를 생성합니다. 적절한 곳에 애너테이션을 활용하여 생성자만 잘 만들어주면 됩니다. @Component를 포함하고 있는 @PersistenceAdapter라는 사용자 애..
-
8장 - 경계 간 매핑하기클린 코드(Clean Code)/만들면서 배우는 클린 아키텍처 요약 2023. 3. 2. 00:01
매핑에 찬성하는 개발자 두 계층을 매핑하지 않으면 양 계층을 같은 모델에 사용해야 하고 두 계층이 강하게 결합된다. 매핑에 찬성하지 않는 개발자 매핑을 위해 너무 많은 보일러플레이트 코드가 생성된다. 많은 유스케이스들이 오직 CRUD만 수행하고 계층에 걸쳐 같은 모델을 사용하기 때문에 계층 사이의 매핑은 과하다 매핑하지 않기 전략 영속성 계층과 유스케이스에서 모두 Account 객체를 사용하는 경우입니다. 이렇게 REST를 위한 JSON 직렬화 애너테이션 또는 ORM 프레임워크를 위한 애너테이션이 필요하게 됩니다. 이렇게 되면 Account 객체에서 웹, 영속성과 관련된 특수한 요구사항에 관심이 없음에도 불구하고 모든 요구사항을 다루게 됩니다. 이제 Account 클래스는 웹, 애플리케이션, 영속성 계층..