신림프로그래머_클린코드.key

Similar documents
歯JavaExceptionHandling.PDF

PowerPoint 프레젠테이션

rmi_박준용_final.PDF

02 C h a p t e r Java

12-file.key

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

FileMaker ODBC and JDBC Guide

JMF3_심빈구.PDF

* Factory class for query and DML clause creation * tiwe * */ public class JPAQueryFactory implements JPQLQueryFactory private f

09-interface.key

목차 INDEX JSON? - JSON 개요 - JSONObject - JSONArray 서울시공공데이터 API 살펴보기 - 요청인자살펴보기 - Result Code - 출력값 HttpClient - HttpHelper 클래스작성 - JSONParser 클래스작성 공공

I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

Spring Boot/JDBC JdbcTemplate/CRUD 예제

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

mytalk

PowerPoint Presentation

FileMaker ODBC and JDBC Guide

Java

JMF2_심빈구.PDF

교육자료

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

PowerPoint 프레젠테이션

초보자를 위한 C# 21일 완성

6장정렬알고리즘.key

03장

NoSQL

PowerPoint 프레젠테이션

자바 프로그래밍

MasoJava4_Dongbin.PDF

PowerPoint 프레젠테이션

Microsoft PowerPoint - 04-UDP Programming.ppt

PowerPoint Presentation

1

Spring Data JPA Many To Many 양방향 관계 예제

슬라이드 1

2002년 2학기 자료구조

14-Servlet

쉽게 풀어쓴 C 프로그래밊

자바-11장N'1-502

PowerPoint Presentation

5장.key

Java XPath API (한글)

04장

JUNIT 실습및발표

JAVA PROGRAMMING 실습 09. 예외처리

Chap12

Microsoft PowerPoint - RMI.ppt

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

ch09

비긴쿡-자바 00앞부속

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

교육2 ? 그림

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

06_sorting

PowerPoint 프레젠테이션

Modern Javascript

Microsoft Word - java19-1-midterm-answer.doc

13ÀåÃß°¡ºÐ

목차 BUG DEQUEUE 의 WAIT TIME 이 1 초미만인경우, 설정한시간만큼대기하지않는문제가있습니다... 3 BUG [qp-select-pvo] group by 표현식에있는컬럼을참조하는집합연산이존재하지않으면결괏값오류가발생할수있습니다... 4

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345])

11강-힙정렬.ppt

untitled

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

JavaGeneralProgramming.PDF

05-class.key

PowerPoint 프레젠테이션

Semantic Consistency in Information Exchange

KYO_SCCD.PDF

슬라이드 1

Frama-C/JESSIS 사용법 소개

OOP 소개

Microsoft PowerPoint - Java7.pptx

API STORE 키발급및 API 사용가이드 Document Information 문서명 : API STORE 언어별 Client 사용가이드작성자 : 작성일 : 업무영역 : 버전 : 1 st Draft. 서브시스템 : 문서번호 : 단계 : Docum

10장.key

오핀 (OFIN) SDK Guide Fintech Mobile SDK Guide - Android V 1.0 OPPFLIB 1

PowerPoint 프레젠테이션


Network Programming

Interstage5 SOAP서비스 설정 가이드

PowerPoint Presentation

01-OOPConcepts(2).PDF

Cluster management software

Microsoft PowerPoint - 03-TCP Programming.ppt

No Slide Title

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

내장서버로사용. spring-boot-starter-data-jpa : Spring Data JPA 사용을위한설정 spring-boot-devtools : 개발자도구를제공, 이도구는응용프로그램개발모드에서유 용한데코드가변경된경우서버를자동으로다시시작하는일들을한다. spri

Microsoft PowerPoint - chap10-함수의활용.pptx

[ 정보 ] 과학고 R&E 결과보고서 Monte Carlo Method 를이용한 고교배정시뮬레이션 연구기간 : ~ 연구책임자 : 강대욱 ( 전남대전자컴퓨터공학부 ) 지도교사 : 최미경 ( 전남과학고정보 컴퓨터과 ) 참여학생 : 박진명 ( 전

C++ Programming

Spring Boot

예외 예외정의예외발생예외처리예외전파 단정 단정의선언 단정조건검사옵션 2

3ÆÄÆ®-11

Secure Programming Lecture1 : Introduction

<4D F736F F F696E74202D20C1A63235C0E520B3D7C6AEBFF6C5A920C7C1B7CEB1D7B7A1B9D628B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

[ 프로젝트이름 ] : Project_Car [ 프로젝트를만든목적 ] : 임의의자동차판매소가있다고가정하고, 고객이원하는자동차의각부분을 Java 를이용하여객 체로생성하고, 그것을제어하는메소드를이용하여자동차객체를생성하는것이목표이다. [ 프로젝트패키지와클래스의내용설명 ] [

PowerPoint Template

2파트-07

<443A5C4C C4B48555C B3E25C32C7D0B1E25CBCB3B0E8C7C1B7CEC1A7C6AE425CBED0C3E0C7C1B7CEB1D7B7A55C D616E2E637070>

[Smali 코드배우기 ] 작성 : 테스트를위해안드로이드앱을리패키징할일이있는데, 이때 smali에대한지식이필요하다. 그래서웹상에있는정보들을모아정리했다. Understanding the dalvik bytecode with the dedexer t

Transcription:

CLEAN CODE 6 11st Front Dev. Team

6 1. 2. 3. checked exception 4. 5. 6.

11 : 2 4 : java (50%), javascript (35%), SQL/PL-SQL (15%) : Spring, ibatis, Oracle, jquery

?

, (, ) ( )

클린코드를 무시한다면

. 6

1.

,,,! ( : http://javacan.tistory.com/entry/oo-basic-2-abstractionandpolymorphism)

,

,

.. ( ),.

. public List<ListingProduct> getadproducts(listingrequest listingrequest) { List<ListingProduct> adproducts = adproductservice.getadproducts(listingrequest); } List<ListingProduct> alternatives = searchservice.search(listingrequest).getproducts(); if (type.equals(power_click)) alternatives = alternatives.sublist(0,5); if (type.equals(chance_shopping)) alternatives = alternatives.sublist(5,10); if (type.equals(all_kill)) alternatives = alternatives.sublist(10,15); if (type.equals(premium)) alternatives = alternatives.sublist(15,20); int limit = 0; if( listingrequest.getviewtype().equals(image) ) { if(listingrequest.istab() && (adproducts.size() % 4)!= 0){ limit = 4 - ( adproducts.size() % 4 ); } else { if ((adproducts.size() % 2)!= 0){ limit = 1; } } } else if (listingrequest.getviewtype().equals(bigimage)){ if(listingrequest.istab() && (adproducts.size() % 2)!= 0){ limit = 1; } } return concatexceptduplicate(alternatives, limit, adproducts );.. +

@Override public List<ListingProduct> getadproductandalternatives(listingrequest listingrequest) { List<ListingProduct> adproducts = adproductservice.getadproducts(listingrequest); List<ListingProduct> alternatives = getalternativeproducts(listingrequest, adproducts); adproducts.addall(alternatives); return adproducts; } private List<ListingProduct> getalternativeproducts (ListingRequest listingrequest, List<ListingProduct> adproducts) { List<ListingProduct> alternatives = getalternativeproductfilteredbytype(listingrequest); int limit = calculatelimit(listingrequest, adproducts); alternatives = alternatives.sublist(0, limit); return alternatives; }

private List<ListingProduct> getalternativeproductfilteredbytype(listingrequest listingrequest) { List<ListingProduct> alternatives = searchservice.search(listingrequest).getproducts(); if (type.equals(power_click)) alternatives = alternatives.sublist(0,5); if (type.equals(chance_shopping)) alternatives = alternatives.sublist(5,10); if (type.equals(all_kill)) alternatives = alternatives.sublist(10,15); if (type.equals(premium)) alternatives = alternatives.sublist(15,20); return alternatives; } private int calculatelimit(listingrequest listingrequest, List<ListingProduct> adproducts) { int limit = 0; if( listingrequest.getviewtype().equals(image) ) { if(listingrequest.istab() && (adproducts.size() % 4)!= 0){ limit = 4 - ( adproducts.size() % 4 ); } else { if ((adproducts.size() % 2)!= 0){ limit = 1; } } } else if (listingrequest.getviewtype().equals(bigimage)){ if(listingrequest.istab() && (adproducts.size() % 2)!= 0){ limit = 1; } } return limit; }

., ( ).,..

2.

,, ( ).,,.

....

...

http://geeksquiz.com/heap-sort/

OLD HEAP SORT ublic void sort(int arr[]) int n = arr.length; // for (int i = n / 2-1; i >= 0; i--) heapify(arr, n, i); // for (int i=n-1; i>=0; i--) { //. int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; } //. heapify(arr, i, 0); // i. // n. void heapify(int arr[], int n, int i) { int largest = i; // largest int l = 2*i + 1; // left. int r = 2*i + 2; // right. } // if (l < n && arr[l] > arr[largest]) largest = l; // if (r < n && arr[r] > arr[largest]) largest = r; // largest if (largest!= i) { int swap = arr[i]; arr[i] = arr[largest]; arr[largest] = swap; } //. heapify(arr, n, largest);

n, l, r?...

HEAP SORT REFACTORING public void sort(int arr[]) { int n = arr.length; } // for (int i = n / 2-1; i >= 0; i--) heapify(arr, n, i); // for (int i=n-1; i>=0; i--) { //. int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; } //. heapify(arr, i, 0); public void sort(int arr[]) { buildheap(arr); heapsort(arr); } private void buildheap(int[] arr) { int sizeofheap = arr.length; for (int i = sizeofheap / 2-1; i >= 0; i--) heapify(arr, sizeofheap, i); } private void heapsort(int[] arr) { int sizeofheap = arr.length; // for (int i=sizeofheap-1; i>=0; i--) { //. int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; //. heapify(arr, i, 0); } }

HEAP SORT REFACTORING public void sort(int arr[]) { buildheap(arr); heapsort(arr); } private void buildheap(int[] arr) { int sizeofheap = arr.length; for (int i = sizeofheap / 2-1; i >= 0; i--) heapify(arr, sizeofheap, i); } private void heapsort(int[] arr) { int sizeofheap = arr.length; // for (int i=sizeofheap-1; i>=0; i--) { //. int temp = arr[0]; arr[0] = arr[i]; arr[i] = temp; //. heapify(arr, i, 0); } } private final int ROOT_INDEX = 0; public void sort(int arr[]) { buildheap(arr); heapsort(arr); } private void buildheap(int[] arr) { int sizeofheap = arr.length; for (int i = sizeofheap / 2-1; i >= 0; i--) heapify(arr, sizeofheap, i); } private void heapsort(int[] arr) { int sizeofheap = arr.length; for (int i = sizeofheap-1; i >= 0; i--) { moveroottoend(arr, i); heapify(arr, i, 0); } } private void moveroottoend(int[] arr, int endindex) { int temp = arr[root_index]; arr[root_index] = arr[endindex]; arr[endindex] = temp; }

HEAP SORT REFACTORING // i. // n. void heapify(int arr[], int n, int i) { int largest = i; // largest int l = 2*i + 1; // left. int r = 2*i + 2; // right. // if (l < n && arr[l] > arr[largest]) largest = l; // if (r < n && arr[r] > arr[largest]) largest = r; // largest if (largest!= i) { int swap = arr[i]; arr[i] = arr[largest]; arr[largest] = swap; //. heapify(arr, n, largest); } } void heapify(int arr[], int heapsize, int rootindex) { int largest = getlargestsubroot( arr, heapsize, rootindex); if (largest!= rootindex) { swap(arr, rootindex, largest); heapify(arr, heapsize, largest); } } private int getlargestsubroot( int[] arr, int heapsize, int rootindex) { int largest = rootindex; int leftsubroot = 2*rootIndex + 1; int rightsubroot = 2*rootIndex + 2; if (leftsubroot < heapsize && arr[leftsubroot] > arr[largest]) largest = leftsubroot; if (rightsubroot < heapsize && arr[rightsubroot] > arr[largest]) largest = rightsubroot; return largest; } private void swap (int[] arr, int left, int right) { int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; }

NEW HEAP SORT public class HeapSort { private final int ROOT_INDEX = 0; public void sort(int arr[]) { buildheap(arr); heapsort(arr); } private void buildheap(int[] arr) { int sizeofheap = arr.length; for (int i=sizeofheap/2-1; i>=0; i--) heapify(arr, sizeofheap, i); } private void heapsort(int[] arr) { int sizeofheap = arr.length; for (int i=sizeofheap-1; i>=0; i--) { moveroottoend(arr, i); heapify(arr, i, 0); } } private void moveroottoend( int[] arr, int endindex) { swap(arr, ROOT_INDEX, endindex); } } void heapify(int arr[], int heapsize, int rootindex){ int largest = getlargestsubroot( arr, heapsize, rootindex); if (largest!= rootindex) { swap(arr, rootindex, largest); heapify(arr, heapsize, largest); } } private int getlargestsubroot( int[] arr, int heapsize, int rootindex) { int largest = rootindex; int leftsubroot = 2*rootIndex + 1; int rightsubroot = 2*rootIndex + 2; } if (leftsubroot < heapsize && arr[leftsubroot] > arr[largest]) largest = leftsubroot; if (rightsubroot < heapsize && arr[rightsubroot] > arr[largest]) largest = rightsubroot; return largest; private void swap (int[] arr, int left, int right) { int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; }

...

3. CHECKED EXCEPTION

EXCEPTION TREE : Checked Exception.. (throw, try-catch.) : Unchecked Exception Exception (, NullPointerException)

CHECKED EXCEPTION.. Exception,. (OCP ) try-catch. ( ).

( ) throws Exception ( checked exception ) Exception Exception catch throws Exception

public interface ListingSearchService { ListingResult search(listingrequest listingrequest) throws Exception; //... } public class ListingDataService { public ListingSearchService searchservice; public ListingData getdata(listingrequest parameter) { ListingData listingdata = new ListingData(); //... ListingResult result = null; try { result = searchservice.search(parameter); } catch (Exception e) { e.printstacktrace(); } //... ListingResult brandresult = searchservice.searchinbrand(parameter); //... return listingdata; } }

throws Exception Exception service Exception catch! service checked exception.

API, checked exception...

4.

API

SEARCH API 2000

SearchRequest( API ). API SearchRequest. (.). ( ).

SEARCH REQUEST BUILDER builder. SearchRequest.

BUILDER.. API API.

. API.?

( )..

package com.wym.search.listing; import com.wym.search.api.*; public class ListingSearchServiceImpl implements ListingSearchService { public static SearchService searchservice = new SearchServiceImpl(); @Override public ListingResult search(listingrequest listingrequest) { SearchRequest request = SearchRequestBuilder.build(listingRequest); SearchResult<Product> result = searchservice.searchproduct(request); return ListingResult.create(result); } }

API package com.wym.search; import com.wym.search.listing.listingrequest; import com.wym.search.listing.listingresult; import com.wym.search.listing.listingsearchservice; public class ListingDataService { public ListingSearchService searchservice; public ListingData getdata(listingrequest parameter) { ListingData listingdata = new ListingData(); //... ListingResult result = searchservice.search(parameter) //... ListingResult brandresult = searchservice.searchinbrand(parameter); //... return listingdata; } }

API ListingSearchService. ( ). Open Closed Principle

...

5.

( ) ( ). main 2 : 1 : 3 : 1.1 : << >> co :

11 APIVersionChecker Controler JSONAssemblerFactory <<interface>> JSONAssembler JSONAssemblerV1 JSONAssemblerV2 1. APIVersionChecker API 2. JSONAssemblerFactory API JSONAssembler.

<<interface>> JSONAssembler JSONAssemblerV1 JSONAssemblerV2 ProductToJSON JSON.. (, ).

public class ProductToJSON { public JSONObject convert(listingproduct product) { JSONObject result = new JSONObject(); result.put("productname", product.getname()); result.put("discountedprice", product.getdiscountedprice()); //... // 3.2.1 result.put("discounticons", makediscounticonsjson()); // 4.0.1 result.put("deliverytext", deliveryinfo.tostring()); //... } }

(ProductToJSON).. ProductToJSON.

: <<interface>> JSONAssembler JSONAssemblerV1 JSONAssemblerV2 <<interface>> ProductToJSON ProductToJSONV1 ProductToJSONV2

: package com.wym.search.json; import com.wym.search.listingdata; import com.wym.search.json.product.productjsonconverter; public class JSONAssemblerV1 implements JSONAssembler { private ListingData data; private ProductToJSON productjsonconverter; public JSONAssemblerV1(ListingData data, ProductToJSON productjsonconverter) { this.data = data; this.productjsonconverter = productjsonconverter; } @Override public JSONData assemble() { JSONData result = new JSONData(); //... return result; } }

: (Factory) ( ) package com.wym.search.json; import com.wym.search.listingdata; import com.wym.search.json.product.productjsonconverterv1; import com.wym.search.json.product.productjsonconverterv2; public class JSONAssemblerFactory { public static JSONAssembler create(listingdata data, int apiversion) { if (apiversion <= 1) { return new JSONAssemblerV1(data, ProductJSONConverterV1.getInstance()); } else if (apiversion <= 2) { return new JSONAssemblerV2(data, ProductJSONConverterV1.getInstance()); } else { return new JSONAssemblerV3(data, ProductJSONConverterV2.getInstance()); } } }

: (Factory). package com.wym.search; import com.wym.search.json.jsonassembler; import com.wym.search.json.jsonassemblerfactory; import com.wym.search.json.jsondata; import com.wym.search.listing.apiversionchecker; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; public class ListingController { public void listing(httpservletrequest request, HttpServletResponse response) { int apiversion = APIVersionChecker.getVersion(request, response); //... JSONAssembler jsonassembler = JSONAssemblerFactory.create(data, apiversion); JSONData result = jsonassembler.assemble(); //... } }

!. DI.

,. (, ).,.

6.

..!

( )

( )

Q & A