전체 글
-
2440 별 찍기 - 3PS/백준 2022. 3. 7. 20:06
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); int loopLeng = Integer.parseInt(buf.readLine()); for (int i = 1; i
-
2439 별 찍기 - 2PS/백준 2022. 3. 6. 21:02
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); int loopLeng = Integer.parseInt(buf.readLine()); for (int i = 1; i
-
2438 별 찍기 - 1PS/백준 2022. 3. 6. 20:43
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); int loopLeng = Integer.parseInt(buf.readLine()); for (int i = 0; i < loopLeng; i++) { for (int j = 0; j
-
item 18 상속보다는 컴포지션을 사용하라책/이펙티브 자바 2022. 3. 4. 23:41
ITEM 18 상속보다는 컴포지션을 사용하라 구현 상속은 위험하다 상속은 코드를 재사용하는 강력한 수단이지만 모든 경우에 최선은 아니다 상위 클래스와 하위 클래스를 모두 같은 프로그래머가 통제하는 패키지 안에서라면 상속도 안전하다 확장할 목적으로 설계되었고 문서화도 잘 되어 있다면 이것도 괜찮다 ####하지만 일반적인 구체 클래스를 패키지 경계를 넘어 다른 패키지의 구체 클래스를 상속하는 일은 위험하다 이번 아이템의 상속은 이러한 구현 상속을 말한다 (인터페이스 상속과는 무관하다) 메서드 호출과 달리 상속은 캡슐화를 깨뜨린다 상위 클래스가 어떻게 구현되느냐에 따라 하위 클래스의 동작에 이상이 생길 수 있다 상속은 상위 클래스와 하위 클래스가 순수한 is-a 관계일 경우에만 사용해야한다 is-a 관계인 경..
-
10818 최소,최대PS/백준 2022. 3. 4. 23:02
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); buf.readLine(); StringTokenizer st = new StringTokenizer(buf.readLine()," "); int iValue = 0; int maxVal = -1000001;..
-
8393 합PS/백준 2022. 3. 3. 23:36
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); int loopLeng = Integer.parseInt(buf.readLine()); int total = 0; for (int i=1; i
-
item 17 변경 가능성을 최소화하라책/이펙티브 자바 2022. 3. 3. 23:31
ITEM 17 변경 가능성을 최소화하라 불변클래스를 만드는 규칙 불변클래스란 인스턴스 내부 값을 수정할 수 없는 클래스다 불변 클래스에 간직된 정보는 객체가 파괴되는 순간까지 변경되지 않는다 불변 클래스는 가변 클래스보다 설계하고 구현하고 사용하기 쉬우며, 오류가 생길 여지도 적고 안전하다 객체의 상태를 변경하는 메서드를 제공하지 않는다 클래스를 확장할 수 없도록 한다 하위 클래스에서 객체의 상태를 변하게 만드는 경우를 막아준다 상속을 막는 대표적인 방법은 클래스르 final로 선언하는것 모든 필드를 final로 선언한다 시스템이 강제하는 수단을 이용해 설계자의 의도를 명확히 드러내는 방법 모든 필드를 private로 선언한다 필드가 참조하는 가변객체를 클라이언트에서 직접 접근해 수정하지 못하도록 한다 ..
-
1924 2007년PS/백준 2022. 3. 2. 22:16
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); String[] dateArray = buf.readLine().split(" "); String[] weekArray = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; int[] endDays = {31, 28, 31, 3..
-
item 16 public 클래스에서는 public 필드가 아닌 접근자 메서드를 사용하라책/이펙티브 자바 2022. 3. 2. 18:27
ITEM 16 public 클래스에서는 public 필드가 아닌 접근자 메서드를 사용하라 public 클래스 인스턴스 필드를 모아놓는 퇴보한 클래스 class Point { public double x; public double y; } 이런 클래스가 public 이라면 데이터 필드에 직접 접근이 가능하여 캡슐화의 이점이 없어진다 데이터 필드에 직접 접근이 가능해지면 아래와 같은 문제가 생긴다 api를 수정하지 않고서는 내부 표현 변경이 불가능하다 불변식을 보장할 수 없다 외부에서 필드에 접근 할 때 부수 작업을 수행할 수 없다 철저한 객체지향 프로그래머는 아래와 같이 작성한다 class Point { private double x; private double y; public Point(double x..
-
item 15 클래스와 멤버의 접근 권한을 최소화하라책/이펙티브 자바 2022. 3. 1. 22:34
ITEM 15 클래스와 멤버의 접근 권한을 최소화하라 잘 설계된 컴포넌트는 내부 데이터와 구현 정보를 외부 컴포넌트로부터 얼마나 잘 숨겼느냐로 판단 가능하다 오직 api를 통해서만 다른 컴포넌트와 소통하며 서로의 내부 동작 방식에는 전혀 개의치 않는다 정보은닉의 장점 시스템 개발 속도를 높인다 여러 컴포넌트를 병렬로 개발할 수 있기 때문 시스템 관리 비용을 낮춘다 각 컴포넌트를 더 빨리 파악하여 디버깅할 수 있고, 다른 컴포넌트로 교체하는 부담도 적기 때문 정보 은닉 자체가 성능을 높여주지는 않지만, 성능 최적화에 도움을 준다 완성된 시스템을 프로파일링해 최적화할 컴포넌트를 정한 다음, 다른 컴포넌트에 영향을 주지 않고 해당 컴포넌트만 최적화할 수 있기 때문 소프트웨어 재사용성을 높인다 외부에 거의 의존..