본문 바로가기

전체 글

(128)
템플릿 메소드 패턴 The Template Method Pattern: Encapsulating Algorithms 커피 및 홍차 클래스 만들기 커피 만드는 것과 홍차 만드는것의 공통부분을 추상화 하자. 동일한 알고리즘 추상화. 물을 끓인다. 뜨거운 물을 이용해 커피 또는 홍차를 우려냄. 만들어진 음료를 컵에 따름. 각 음료에 맞는 첨가물을 추가한다. prepareRecipe() 추상화하기 1. 비슷한 행위를 같은이름으로 통일해서 새로운 메소드를 만듬. // Coffee void prepareRecipe() { boilWater(); brewCoffeeGrinds(); purInCup(); addSugarAndMilk(); } // Tea void prepareRecipe() { boilWater(); steepTeaBag(); purInCup(); addLemon(); } // 메소드 통일 void prepareRe..
Dynamic Programming A method for solving a complex problem by breaking it down into collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions. 'dynamic' was chosen by Bellman to capture the time varing aspect of the problems. 'programming' didn't refer to computer programming but to finding an optimal program n the same way. It only works on problems with optimal su..
Dijkstra's Algorithm one of the most famous and widely used algorithms the shortest path between the vertices. Edsger Dijkstra, a Dutch programmer Useful for GPS - finding fastest route Network Routing - finds open shortest path for data Biology - used to model the spread of viruses among humans Airline tickets - finding cheapest route to your destination Many other uses! thr first thing is we need to do is adding a..
Graph Traversal Graph Traversal Uses Peer to peer networking Web crawlers Finding the closest matches/recommendations Shortest path problems(GPS, Solving mazes, AI) In a Tree, depth first means moving away from the route. unlike a tree, we need to specify the starting point. when it comes to depth first traversal, it is finding one neighbor following one neighbor. It is really important, we remember where we've..
Graphs Essential Graph Terms Vertex - a node Edge - connection between nodes Weighted / Unweighted - values assigned to distances between vertices. each edge has value associated with it or not. Directed / Undirected - directions assigned to distanced between vertices one way or both way relationship or not. the polarity of the edges. facebook : directed graphs, instagram: undirected graphs. Two diffen..
Chapter 17 17 냄새와 휴리스틱 Smells and Heuristics 주석 C1: 부적절한 정보 변경이력은 소스를 번잡하게 만듬. 주석은 코드와 설계에 기술적인 설명만. C2: 쓸모없는 주석 오래되서 쓸모없는 주석은 즉시 삭제. C3: 중복된 주석 구구절절 설명하는 중복된 주석 C4: 성의없는 주석 간결하고 명표하게 작성. C5: 주석처리된 코드 소스코드 관리 시스템이 기억하기 때문에 쓸모없는 코드는 주석처리보다 지우자. 환경 E1: 여러단계로 빌드해야 한다. 빌드는 간단히 한 단계로, 한 명령으로 빌드할 수 있어야 한다. E2: 여러단계로 테스트해야 한다 모든 단위 테스트는 한 명령으로 돌려야 함. 함수 F1: 너무 많은 인수 함수의 인수 개수는 작을수록, 아예 없으면 더 좋음. F2: 출력 인수 함수에서 어떤..
Chapter 15, 16 15 JUnit 들여다보기 JUnit 프레임워크 ComparisonCompactor 모듈 두 문자열을 받아 차이를 반환. ABCDE 와 ABCXDE 를 받아 를 반환. ComparisonCompactorTest.java package junit.tests.framework; import junit.framework.ComparisonCompactor; import junit.framework.TestCase; public class ComparisonCompactorTest extends TestCase { public void testMessage() { String failure= new ComparisonCompactor(0, "b", "c").compact("a"); assertTrue("a ex..
Chapter 13, 14 13 동시성 Concurrency 객체는 처리의 추상화다. 스레드는 일정의 추상화다. - 제임스 O.코플리엔 동시성과 깔끔한 코드는 양립하기 매우 어려움. 동시성이 필요한 이유? 동시성은 결합 coupling 을 없애는 전략 : 무엇 what 과 언제 when 을 분리하는 전략. 서블릿 servlet 모델. 서블릿은 웹 호은 EJB 컨테이너 에서 돌아가는데 동시성을 부분적으로 관리함. 웹요청이 들어올때마다 웹서버는 비동기식으로 서블릿을 실행. 동시성이 필요한 상황이 존재. 동시성은 다소 부하를 유발 동시성은 복잡 일반적으로 동시성 버그는 재현하기 어려움 동시성을 구현하려면 흔히 근본적인 설계전략을 재고. 동시성 방어 원칙 단일 책임 원칙 SRP 주어진 메서드/클래스/컴포넌트를 변경할 이유가 하나여야 한다..