본문 바로가기

728x90

Java

(10)
DI & IoC DI (Dependency Injection) - 의존성 주입 public class Main { public void main(String[] args) { Person jobth = new Person(“잡th”); jobth.buy(); } } class Person { … void buy() { SamsongPhone samsong = new SamsongPhone(“삼송”); System.out.println(name + "님이 " + samsong.getName() + “폰을 샀습니다.”); } … } - Person 클래스는 내부적으로 SamsongPhone 클래스를 생성 - 매번 생성하는 것 보다, 생성 되어야 하는 SamsongPhone에 @Component를 생성 시키는 Person에 ..
오버라이딩 class Car{ int wheelDrive; public Car(int wheelDrive) { this.wheelDrive = wheelDrive; } void drive(){ System.out.println("기름을 써서 출발 구동은?= " + this.wheelDrive); } } class EvCar extends Car{ int chargeEV; public EvCar(int wheelDrive, int chargeEV) { super(wheelDrive); this.chargeEV = chargeEV; } @Override void drive(){ System.out.println("전기를 써서 출발 " + "전기충전량= " + this.chargeEV + " 구동은?= " + this...
인터페이스 인터페이스를 활용하면 객체지향을 조금 더 편리하게 구현할 수 있다. public interface Car { void move(); } public class FastCar implements Car { @Override public void move() { System.out.println("빠르게 달립니다."); } } public class SnowCar implements Car { @Override public void move() { System.out.println("겨울에 잘 달립니다."); } } public class SuperCar implements Car { @Override public void move() { System.out.println("슈퍼하게 달립니다."); } } ..
메소드 레퍼런스 1. 메소드 레퍼런스(Method References) Consumer func = text -> System.out.println(text); func.accept("Hello"); Consumer func = System.out::println; func.accept("Hello"); Static 메소드 레퍼런스 Instance 메소드 레퍼런스 Constructor 메소드 레퍼런스 2. Static 메소드 레퍼런스 public class Example { public static void main(String[] args) { Executable exe = text -> Printer.printSomething(text); Executable exe2 = Printer::printSomething; ..
람다 표현식 package section_1; import java.util.function.*; public class Foo { public static void main(String[] args) { Foo foo = new Foo(); foo.run(); } private void run() { int baseNumber = 10; // 로컬 클래스 - 쉐도잉 class LocalClass { void printBaseNumber() { int baseNumber = 11; System.out.println(baseNumber); } } // 익명 클래스 - 쉐도잉 Consumer integerConsumer = integer -> { int baseNumber1 = 11; System.out.println(..
Java의 함수형 인터페이스 import java.util.function.*; public class Foo { public static void main(String[] args) { Function plus10 = (i) -> i + 10; // UnaryOperator plus11 = (i) -> i + 11; Function multiply2 = (i) -> i * 2; // 고차함수 생성 후 실행 Function multiply2AndPlus10 = plus10.compose(multiply2); System.out.println(multiply2AndPlus10.apply(10)); // 고차함수 앞에서 부터 실행 System.out.println(plus10.andThen(multiply2).apply(10)); //..
함수형 인터페이스와 람다 표현식 함수형 인터페이스 - 추상 메서드를 딱 하나만 가지고 있음 - Single Abstract method 인터페이스 - @FunctionInterface 어노테이션을 가지고 있는 인터페이스 @FunctionalInterface public interface RunSomething { int doIt(int num); } 람다 표현식 - 함수형 인터페이스의 인스터를 만드는 방법으로 쓰일 수 있음 - 코드 줄이기 가능 - 메소드의 매개변수, 리턴 타입, 변수를 만들어 사용 가능 public class Foo { public static void main(String[] args) { RunSomething runSomething = num -> num + 10; } } 자바에서 함수형 프로그래밍 - 함수를 F..
비즈니스 요구사항 설계 설계를 하는 이유 - 100% 정해지지 않는다. (완벽한 기획은 없음) - 자주 변경된다. (이게 젤 빡치는데 그 만큼 시장은 자주 바뀌고 고객의 마음도 자주 바뀜) - 그렇기 때문에 변경에 대처 가능한 프로그램을 개발해야 함 예제 - 회원 1. 회원은 가입 후 조회를 한다. 2. 등급이 있다. 3. DB 뭐 쓸지 모르겠다. (변경 가능성 o) - 주문 1. 회원은 주문을 한다. 2. 할인 정책이 있다 없을 수도 있다. (변경 가능성 o) 3. 고정 금액 할인율이 있다. (변경 가능성 o) 회원 주문 - 구현, 종속 관계를 내포하고 있는 클래스 다이어그램

728x90