다형성3 [java] 직접 구현한 List 추상화 (feat. 의존관계 주입) 목차복잡한 로직을 수행하는 배치 프로그램이 있다고 가정한다.로직은 매개변수로 넘어온 인자만큼 루프를 돌면서 list의 앞부분에 데이터를 넣는 로직이다.(앞부분인게 중요)배치프로그램 코드를 점점 개발자들이 리팩토링 했다는 스토리다.Ver 1: ArrayList 사용의 성능 문제package collection.test;import collection.list.MyArrayList;public class BatchProcessorV1 { // MyArrayList에 직접 의존(bad) private final MyArrayList list = new MyArrayList(); //엄청 복잡한 로직이라고 가정 public void logic(int size) { long st.. IT/development 2025. 1. 5. [java] 다형성을 이용한 중복 코드 분리 (feat. 익명 클래스) 목차 [java] 다형성을 이용한 중복 코드 분리 (feat. 정적 중첩 클래스)목차Ex2Mainpackage nested.anonymous.ex;public class Ex2Main { public static void helloThor() { System.out.println("프로그램 시작"); //코드 조각 시작 for (int i = 0; i helloThor(), helloLoki()의 코드 조각 시작 ~ 종료부분은 중복yaga.tistory.com위 포스팅에서 이어지는 내용익명 클래스 활용1package nested.anonymous.ex;public class Ex1RefMainV2 { public static void hello(Process process) { Syst.. IT/development 2024. 12. 25. [java] 다형성을 이용한 중복 코드 분리 (feat. 정적 중첩 클래스) 목차Ex2Mainpackage nested.anonymous.ex;public class Ex2Main { public static void helloThor() { System.out.println("프로그램 시작"); //코드 조각 시작 for (int i = 0; i helloThor(), helloLoki()의 코드 조각 시작 ~ 종료부분은 중복코드다.리팩토링 😃Godpackage nested.anonymous.ex;public interface God { void god();}Ex2RefMainV1package nested.anonymous.ex;public class Ex2RefMainV1 { public static void hello(.. IT/development 2024. 12. 25. 이전 1 다음