Skip to Content
실무로 통하는 클린 코드
book

실무로 통하는 클린 코드

by 막시밀리아노 콘티에리, 이태영
August 2024
Beginner to intermediate
488 pages
11h 1m
Korean
Hanbit Media, Inc.
Content preview from 실무로 통하는 클린 코드
251
14
if 문
함께 보기
마틴 파울러의 ‘플래그 인수’ (
https://oreil.ly/RXti-
)
14.4
switch
/
case
/
else
if
문 대체하기
문제
스위치와 케이스가 있는 제어 구조가 있습니다.
해결
다형성 객체로 대체하세요.
설명
스위치는 너무 많은 결정을 함께 결합하고, 새로운 조건이 추가될 때마다 주요 알고리듬
이 변경되어 병합 충돌이 발생하며 개방-폐쇄 원칙(
14
.
3
절 ‘
boolean
변수 재구성하기’ 참조 )
을 위반합니다. 또한 중복된 코드와 매우 큰 메서드 생성을 유발합니다. 이러한 문제를 해결하
기 위해서는 상태 패턴을 사용해 전환을 모델링하고, 전략 패턴이나 메서드 객체를 사용해 분
기를 선택하는 개방-폐쇄 원칙에 따라 계층을 생성하거나 구성해야 합니다.
다음 예제는 여러 가지 오디오 형식을
MP3
로 변환하는 예제입니다.
class Mp3Converter {
convertToMp3(source, mimeType) {
if(mimeType.equals("audio/mpeg")) {
this.convertMpegToMp3(source)
} else if(mimeType.equals("audio/wav")) {
this.convertWavToMp3(source)
} else if(mimeType.equals("audio/ogg")) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

데이터 과학을 위한 통계(2판)

데이터 과학을 위한 통계(2판)

이준용, 피터 브루스, 앤드루 브루스, 피터 게데크
클라우드 네이티브 애플리케이션 디자인 패턴

클라우드 네이티브 애플리케이션 디자인 패턴

카순 인드라시리, 스리스칸다라자 수호티얀
데이터 엔지니어를 위한 97가지 조언

데이터 엔지니어를 위한 97가지 조언

Tobias Macey, 임혜연(Lim Hye Yeon)

Publisher Resources

ISBN: 9791169212779