분류 전체보기
-
이팩티브 자바 Item 1 - 생성자 대신 정적 팩터리 메서드를 고려하라언어/Effective Java 2024. 5. 27. 11:06
인스턴스를 생성하는 방법은 (1) public 생성자 (2) 정적 팩터리 메서드 사용이 있다. 이때, 정적 팩터리 메서드 메서드를 사용하면 다음과 같은 장점이 있다.1. 생성 목적에 대한 이름 표현이 가능하다. (객체 생성의 가독성이 높아진다) 생성자는 클래스명으로만 구현할 수 있지만, 정적팩터리 메서드는 자신의 이름을 가질 수 있다.new 키워드를 통해 생성자를 생성하면, 해당 생성자의 인수 순서와 내부구조를 알고 있어야 목적에 맞게 객체를 생성할 수 있다는 번거로움 존재정적 팩터리 메서드 구현 시 자주 사용되는 이름이 있다! from: 매개변수를 받아서 해당 타입의 인스턴스 반환of: 여러 매개변수 받아서 적합한 인스턴스 반환valueOf : from, of보다 자세한 버전 instance, get..
-
템플릿 메서드(Template Method) 패턴언어/디자인패턴 2024. 5. 26. 22:31
템플릿 메서드 패턴이란? 여러 클래스에서 공통으로 사용하는 메서드를 템플릿화하여 상위 클래스에서 정의하고, 하위 클래스마다 세부 동작 사항을 다르게 구현하는 패턴이다.변하지 않는 기능은 상위 클래스에 만들어두고 자주 변경되어 확장할 기능은 하위 클래스에서 만들도록 하는 것이다.상속이라는 기술을 극대화하여, 알고리즘의 뼈대를 맞추는 것에 초점을 둔다. 공통된 부분에서 다른 부분 혹은 확장 가능한 부분을 제공하는 느낌! (공통을 따로 뺀다는 느낌보다 공통은 그대로 두고, 바뀌는 부분만 새로 만들도록 한다!) AbstractClass(추상 클래스) : 템플릿 메소드를 구현하고, 템플릿 메소드에 돌아가는 추상 메서드를 선언한다. 이 추상 메서드는 하위클래스 ConcreateClass에서 구현된다.Concrete..
-
전략 패턴 (Strategy)언어/디자인패턴 2024. 5. 26. 21:41
전략 패턴이란?실행(런타임) 중 알고리즘 전략을 선택하여 객체 동작을 실시간으로 바뀌도록 하는 행위 디자인 패턴이다.전략은 일종의 알고리즘 혹은 특정 목표를 수행하기 위한 행동 계획을 의미한다.어떤 일을 수행하는 알고리즘이 여러가지 일때, 동작들을 미리 전략으로 정의하여, 손쉽게 교체하는 방법이다. 알고리즘 변형이 빈번할 경우 적합하다. 전략 인터페이스 : 모든 전략 구현체에 대한 공용 인터페이스 전략 객체(concreate): 전략 인터페이스 구현체 컨텍스트(Context) : 알고리즘을 실행할 때 해당 알고리즘과 연결된 전략 객체 메서드 호출 (전략을 사용하는 큰 기능)클라이언트 : 전략 객체 전달, 해당 전략 사용해서 결과 얻음class Client{ public static void main(St..
-
입출금 내역 분석기 (1) - 응집도와 결합도에 따른 클래스 분리언어/객체지향 2024. 5. 24. 17:12
1. 목표단일책임원칙을 배워보자응집도와 결합도에 대해 생각해보자 2. 요구사항텍스트 파일이 콤마로 분리된 값으로 주어진다. 이 값을 파싱해서 결과를 얻을 것이다.입출금 내역의 총 수입과 총 지출은 각각 얼마인가? 결과는 양수인가 음수인가?특정 달엔 몇 건의 입출금 내역이 발생했는가?지출이 가장 높은 상위 10건은 무엇인가?돈을 가장 많이 소비하는 항목은 무엇인가?30-01-2017,-100,Deliveroo//..3. KISS 원칙 keep it short and simple 원칙을 의미한다. 코드 설계나 내용을 불필요하게 복잡하게 만들지 말자는 원칙 public class BankTransactionAnalyzerSimple { private static final String RESOURCES ="..
-
Github Action으로 ecr 업로드 하기Infra/CI&CD 2024. 5. 16. 23:39
ECR이란?AWS에서 제공하는 관리형 컨테이너 이미지 레지스트리 서비스AWS IAM을 사용하여 리소스 기반 권한을 가진 프라이빗 리포지토리 지원지정된 사용자 혹은 EC2 인스턴스가 컨테이너 리포지토리 및 이미지에 엑세스 가능하다. Docker hub와 같이 이미지를 저장할 수 있는 저장소와 같은 개념이다.GithubAction과 같이 사용하면, 워크플로우의 결과로 docker Image를 생성하고, ECR에 간단하게 업로드 할 수 있다.ECR 생성 아마존에서 Elastic Container Registry검색해서 시작하자Repository를 하나 만들어보자! 다음으로 IAM으로 넘어가서 User와 Policy를 생성하자정책 생성을 눌러서 새로운 정책을 생성하자 여기서 정책은 ECR에 접근하고, 이미지를 ..
-
Github Action 기본 사용법Infra/CI&CD 2024. 5. 16. 22:33
CI/CD란?소프트웨어 개발 과정에서 효율성과 신속성을 극대화하는 자동화된 프레임워크 개발부터 운영까지 소프트웨어 개발 라이프사이클의 모든 단계를 아우른다.크게 지속적 통합, 지속적 전달, 지속적 배포로 구분 된다. 지속적 통합 (CI)개발자들이 작업한 코드를 주기적으로 공유레퍼지토리에 병합, 코드 통합을 자동화하는 과정 모든 변경사항은 자동 빌드 및 테스트를 거쳐 메인 브랜치에 통합된다.코드 충돌을 최소화하며, 소프트웨어 품질을 유지하고, 배포 준비 상태를 지속적으로 유지할 수 있다.BUILD -> TEST -> MERGE 과정을 아우름 특히! TEST가 매우 매우 중요하다. 지속적 전달 (CD - Continuous Delivery)코드 변경사항이 자동으로 빌드 및 테스트를 거쳐 실제 운영 환경에 ..
-
스프링 부트 모니터링 (3) - 프로메테우스와 그라파나 활용하기Web/환경설정 관련 2024. 5. 14. 18:23
프로메테우스란?시간이 지남에 따라 추이가 변하는 데이터를 메트릭이라고 한다. 대표적으로 CUP 사용량, 메모리 사용량등을 생각할 수 있는데, SpringBoot는 메트릭의 수집을MicroMeter 모듈을 내장한 엑추에이터가 담당한다.이때, 메트릭은 시간이 흐를수록 계속 쌓이게 되고, Application 메모리가 증가하여, 지속적으로 쌓이는 메트릭을 모두 커버할 수 없다. 따라서 메트릭 전용 외부 DB를 연결해 두는데, 이것이 프로메테우스이다. 프로메테우스는 마이크로미터가 수집한 메트릭 데이터를 일정시간 간격으로 PULL해서 DB에 수집한다.이때, MicroMeter Prometheus구현체가 필요하다. 왜냐면, 마이크로미터는 수집한 메트릭을 JSON 형식으로 전달하지만,프로메테우스는 JSON 데이터를..
-
스프링 부트 모니터링(2.2) - Info 엔드포인트 탐구Web/환경설정 관련 2024. 5. 14. 16:49
info엔드포인트를 통해 애플리케이션 관련 정보를 확인할 수 있다.info 엔드포인트는 기본적으로 아무것도 제공하지 않는다. 하지만 적절히 커스텀해서 원하는 정보를 노출할 수 있다. 1. 다양한 정보 표시해보기application.properties에 다음과 같은 내용을 추가해보자info.app.name= Spring Boot Actuator Info Applicationinfo.app.description=Spring Boot application that explores the /info endpointinfo.app.version=1.0.0management.info.env.enabled=truehttp://localhost:8080/actuator/info에 접근하면, 위와 같이 미리 적어둔 정보..