전체 글
-
30장 - 요소의 가시성을 최소화하라Kotlin/Effective Kotlin 요약 2023. 3. 16. 00:01
가시성과 클래스 클래스는 만족해야 하는 상태에 대한 규약들이 존재합니다. 이런 규약을 모르는 사람은 클래스의 상태를 마음대로 변경할 수 있습니다. 이렇게 되면 클래스의 불변성이 무너질 가능성이 있습니다. 일반적으로 코틀린에서는 구체 접근자의 가시성을 제한해서 모든 프로퍼티를 캡슐화하는 것이 좋습니다. 가시성이 제한될 수록 클래스의 변경을 쉽게 추적할 수 있으며, 프로퍼티의 상태를 더 쉽게 이해할 수 있습니다. 이로 인해 동시성을 처리할 때도 더 안전해집니다. 가시성 한정자 - public(디폴트) : 어디에서나 볼 수 있음 - private : 클래스 내부에서만 볼 수 있음 - protected : 클래스와 서브클래스 내부에서만 볼 수 있음 - internal : 모듈 내부에서만 볼 수 있음 예를 들어 ..
-
29장 - 외부 API를 랩해서 사용하라Kotlin/Effective Kotlin 요약 2023. 3. 15. 00:01
외부 API를 warp 해서 사용하면 얻는 자유와 안정성 - 문제가 있다면 래퍼만 변경하면 되어, API 변경에 쉽게 대응할 수 있다 - 프로젝트 스타일에 맞춰 API의 형태를 조정할 수 있다 외부 API를 warp해서 얻는 단점 - 래퍼를 따로 정의해야 한다. - 래퍼는 프로젝트 내부에서만 유효하며, 어떤 래퍼들이 존재하는지 따로 확인해야 한다 결론 장단점을 잘 이해하고 라이브러리가 얼마나 안정적인지, 사용자에게 인기가 많은지에 따라 API를 랩 할지 말지 잘 결정해야 합니다. 만약 인기가 없고 새로 만들어진 라이브러리라면 신중하게 사용을 결정하고, 사용하기로 했다면 클래스와 함수로 랩 하는 것을 고려하기 바랍니다.
-
28장 - API 안정성을 확인하라Kotlin/Effective Kotlin 요약 2023. 3. 14. 00:01
표준과 안정성 세상의 자동차의 운전법이 모두 다르다면 운전하기 전에 운전 방법을 계속 배워야 합니다. 이처럼 일시적으로 사용되는 인터페이스를 배우는 일은 귀찮은 일입니다. 따라서 운전 방법은 안정적이면서 표준적인 것이 좋습니다. 프로그래밍에서도 최대한 안정적이고 표준적인 API를 선호합니다. 하지만 좋은 API를 한 번에 설계할 순 없습니다. API 제작자는 이를 계속해서 개선해나가기 원합니다. 보통은 이에대한 해결책으로 버저닝을 통해 관리합니다. 또한 사용자에게 API에 대한 정보를 제공하는 것도 중요합니다. 예를 들어 Experimental 메타 어노테이션을 붙이면 해당 요소가 안정적이지 않다는 것을 알려줍니다. 또한 Deprecated 어노테이션을 활용하여 해당 API를 통해 변경될 것을 미리 알려..
-
27장 - 변화로부터 코드를 보호하려면 추상화를 사용하라Kotlin/Effective Kotlin 요약 2023. 3. 13. 00:01
물 위를 걷는 것과 명세서로 소프트웨어를 개발하는 것은 쉽다. 둘 다 동결되어 있다면.. 함수와 클래스 등의 추상화로 실질적인 코드를 숨기면, 사용자가 세부 사항을 알지 못해도 괜찮다는 장점이 있습니다. 추상화의 다양한 사례 1단계 : 상수 리터럴(매직넘버)은 아무것도 설명하지 않습니다. 이를 상수로 빼어낸다면 훨씬 쉽게 이해할 수 있습니다. //지양 if(text.length < 7) return false //지향 const val MIN_PASSWORD_LENGTH = 7 if(text.length < MIN_PASSWORD_LENGTH) return false 2단계 : 함수 토스트 메시지를 자주 출력해야 한다면 다음과 같은 코드를 작성할 수 있습니다. Toast.makeText(this, mes..
-
26장 - 함수 내부의 추상화 레벨을 통일하라Kotlin/Effective Kotlin 요약 2023. 3. 12. 00:01
추상화란? 컴퓨터 과학에서 추상화는 복잡한 자료, 모듈, 시스템 등으로부터 핵심적인 개념 또는 기능을 간추려 내는 것을 말합니다. 추상화와 자동차 예시 자동차 내부에서는 엔진, 알터네이터, 서스펜션 등의 여러 가지 요소들이 함께 자동차가 움직일 수 있게 만듭니다. 운전을 할 때 이런 요소들을 실시간으로 이해하고 조정해야 한다면, 자동차 운전은 굉장히 힘들 수 있습니다. 하지만 운전자는 자동차를 조종하는 인터페이스(핸들과 페달 등)를 사용하는 방법만 알면 됩니다. 가솔린 자동차, 천연가스 자동차, 경유 자동차, 전기 자동차 모두 운전 방법이 대부분 같습니다. 자동차가 내부적으로 여러 반도체와 특수한 시스템을 도입해도, 운전자는 상관없이 운전할 수 있습니다. 자동차는 굉장히 잘 만들어진 인터페이스로 굉장히 ..
-
12장 - 아키텍처 스타일 결정하기클린 코드(Clean Code)/만들면서 배우는 클린 아키텍처 요약 2023. 3. 11. 00:01
언제 육각형 아키텍처 스타일을 사용하고, 전통적인 계층형 아키텍처 스타일을 사용해야 할까? 도메인이 왕이다 외부 시스템에 대한 의존성 등의 변화로부터 자유롭게 도메인 코드를 개발할 수 있는 것이 육각형 아키텍처 스타일의 주요 특징이라는 것은 명확합니다. 영속성이나 다른 기술적인 측면에 대해서 함께 생각할 필요가 없어지게 되면서 도메인에 대해 가장 잘 고려할 수 있게 됩니다. 만약 도메인 코드가 애플리케이션에서 가장 중요한 것이 아니라면 이 아키텍처 스타일은 필요하지 않습니다. 경험이 여왕이다 과거에 했던 일에 편함을 느끼는데 무언가를 바꿀 이유를 있을까? 육각형 아키텍처에 대한 확신이 없다면 작은 모듈에 먼저 시도해 보는 것이 좋습니다. 이후에 자신만의 아이디어를 추가해서 편하게 느껴지는 스타일로 개발하..
-
11장 - 의식적으로 지름길 사용하기클린 코드(Clean Code)/만들면서 배우는 클린 아키텍처 요약 2023. 3. 10. 00:01
지름길을 방지하기 위해서는 먼저 지름길 자체를 파악해야 합니다. 소프트웨어는 말랑말랑하기(쉽게 변경될 수 있기) 때문에 지름길을 먼저 취하고 나중에 고치는 것이 더 경제적일 수 있습니다. 왜 지름길은 깨진 창문 같을까? 깨진 창문 이론이란? 번호판 없는 차 한 대를 주거환경이 높고 낮은 환경에 주차하였을 때 주거환경이 낮은 곳에서는 24시간이 지나기 전에 중요 부품들이 도난당했으며 주거환경이 높은 곳에서는 일주일 동안 전혀 손을 타지 않았습니다. 하지만 일부로 창문을 깨뜨리자 짧은 시간동안 행인들에 의해 망가졌습니다. 이로 2가지를 알 수 있습니다 - 기물 파손이 흔한 동네에서는 방치된 차를 도둑질하거나 망가뜨리는 일이 더 쉽게 일어난다. - 좋은 동네라도 차의 창문이 깨져있다면 차를 망가뜨리는 일이 쉽..
-
10장 - 아키텍처 경계 강제하기클린 코드(Clean Code)/만들면서 배우는 클린 아키텍처 요약 2023. 3. 9. 00:01
일정 규모 이상의 모든 프로젝트에서는 시간이 지나면서 아키텍처가 서서히 무너지게 됩니다. 계층 간의 경계가 약화되고, 코드는 점점 더 테스트하기 어려워지게 됩니다. 해당 장에서는 아키텍처 내의 경계를 강제하는 방법과 아키텍처 붕괴에 맞서 싸우기 위해 취할 수 있는 전략을 살펴보고자 합니다. 경계와 의존성 경계를 강제한다는 것은 어떤 것을 의미할까요? 의존성 규칙에 따르면 경계는 항상 안쪽으로 향해야 합니다. 1. 접근제한자 public, private, protected에 대해서만 대부분 알고 있으며 default 제한자를 잘 모릅니다. default 제한자는 패키지를 통해 클래스들을 응집적인 모듈로 만들어줍니다. 모듈 내의 클래스들은 서로 접근 가능하지만 패키지 바깥에서는 접근할 수 없습니다. 이제 모..