Programming 94

코드 품질올리기, 코드 설계 - 3 성숙한 클래스 만들기 (2/3)

1) 응집도를 저해하는 것들 static 메서드는 인스턴스 변수를 사용할 수 없습니다. 따라서 데이터와 데이터 로직사이에 괴리가 생깁니다. 즉 응집도가 낮아집니다. static 메서드는 로그 출력 전용메서드, 포맷 변환 전용 메서드, 팩토리 메서드등 응집도와 관계없는 기능을 static 으로 정의하면 좋습니다. private 생성자, 팩토리 메서드를 사용해 목적에 따라 초기화 하기 올바른예 class GiftPoint { private static final int MIN_POINT = 0; private static final int STANDARD_MEMBERSHIP_POINT = 3000; private static final int PREMIUM_MEMBERSHIP_POINT = 10000; pr..

Programming/기타 2023.08.30

코드 품질올리기, 코드 설계 - 3 성숙한 클래스 만들기 (1/3)

1) 클래스는 클래스 하나로도 잘 동작할 수 있도록 설계해야 합니다. 또한 복잡한 초기 설정을 하지 않아도 곧바로 사용할 수 있게 해야합니다. 모든 클래스는 자기방어 임무가 있습니다. 다른 클래스를 사용하여 초기화하거나 유효성 검사를 해야하는 클래스는 그 자체로는 안전하게 사용할 수 없는 미성숙한 클래스 입니다. 올바른 예 Class Money { final int amount; final Currency currency; Money(int amount, Currency) { if (amount < 0){ throw new IllegalArgumentException("금액은 0 이상의 값을 지정해 주세요."); } if (currency == null) { throw new NullPointerExce..

Programming/기타 2023.08.30

코드 품질올리기, 코드 설계 - 2 분기중접 줄이기 (3/3)

이미 존재하는 기능을 다른 방법으로 구현할 필요는 없습니다. 1) 조건을 만족하는 요소가 컬렉션 내부에 하나라도 포함되어 있는 경우 잘못된 예 boolean hasPrisonKey = false; // items List 자료형 for (Item each : items){ if (each.name.equals("감옥열쇠")){ hasPrisonKey = true; break; } } 이 기능을 간단하게 아래와 같이 구현할 수 있습니다. 올바른 예 boolean hasPrisonKey = items.stream().anyMatch( item -> item.name.quals("감옥열쇠") ); 이렇게 anyMatch를 사용하면 for 반복문과 if 조건문을 사용할 필요도 없이 한 줄로 처리를 완료할 수 있..

Programming/기타 2023.08.28

코드 품질올리기, 코드 설계 - 2 분기중접 줄이기 (1/3)

가. 이해하기 어렵게 만드는 분기중첩 조건 분기는 조건에 따라 처리 방식을 다르게 하는데 사용되는 프로그래밍 언어의 기본 제어 구조입니다. 그런데 조건 분기를 어설프게 사용하면 악마가 되어 개발자를 괴롭힙니다. 잘못된 예 if ( 0 < member.hitPoint ) { //살아 있는가? if (member.canAct()) { //움직일 수 있는가? if(magic.costMagicPoint

Programming/기타 2023.08.28

JSESSIONID만으로 세션 유효성 검증하는 방법

1. 아래와 같이 Interceptor Class를 정의한다. Prehandler에 세션체크 로직을 정의한다. package egovframework.example.com; import javax.servlet.ServletContext; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.slf4j.Logger; import org.slf4j.loggerFactory; import org.springframework.web.servlet.ha..

Programming/Java 2023.08.28

코드 품질올리기, 코드 설계 - 1 이름의 중요성과 모델링

"내 코드가 이상한가요" 센바다이아 著 를 읽고 정리한 글입니다. 가. 이름의 중요성과 모델링 1. 기술을 중심으로 이름을 짓거나, 일련번호를 매겨 이름을 지으면 코드에서 어떠한 의도도 읽어낼수 없습니다. 읽고 이해하는데 시간이 오래 걸릴 뿐더러 기능을 일일이 매핑시킨 알람표(스프레드시트)는 바쁜업무로 인해 유지보수가 거의 이루어 지지 않습니다. 권장하지 않는 예 1) 기술중심 명명 class MemoryStateManager { void changeIntValue01 (int changeValue) { updateState01(); ... } 종류 예 컴퓨터 기술 유래 memory, cache, thread, register 등 프로그래밍 기술 유래 function, method, class, modu..

Programming/기타 2023.08.28

yarn install 시 발생하는 오류 해결

우선 Registry 주소 확인하기 $ npm config get registry $ yarn config get registry Registry 주소 변경하기 $ yarn config set registry https://registry.npmjs.org/ NPM이나 yarn으로 아래 오류 발생할때 There appears to be trouble with your network connection. Retrying... 일반적인 방법 $ yarn config delete proxy $ yarn config delete https-proxy $ yarn install --network-timeout 600000 $ yarn cache clean 위 것도 안되면 yarn.lock 파일 지워보자.. 난 이..

어플리케이션 구성요소별 Naming Convention

Oracle 가이드는 다음과 같으니 참고하시길 https://www.oracle.com/java/technologies/javase/codeconventions-introduction.html Code Conventions for the Java Programming Language: 1. Introduction We’re sorry. We could not find a match for your search. We suggest you try the following to help find what you’re looking for: Check the spelling of your keyword search. Use synonyms for the keyword you typed, for example,..

Programming/기타 2023.06.26

NPM 운영환경으로 이전할때 발생하는 버그 및 FIX

[에러] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. 본 포스팅은 아래의 링크를 참조하였습니다. 제 삽질을 덜어주셔서 감사합니다. https://velog.io/@black-pepper/Invalid-options-object.-Dev-Server-has-been-initialized-using-an-options-object-that-does-not-match-the-API-schema [에러] Invalid options object. Dev Server has been initialized using an options object tha..