System Design

์‹ค๋ฌด์—์„œ ์ž์ฃผ ์ ‘ํ•˜๊ฒŒ ๋˜๋Š” ์•ˆํ‹ฐ ํŒจํ„ด

ํ”„๋กœ๊ทธ๋ž˜๋จธ ์˜ค์›” 2024. 12. 26.

์•ˆํ‹ฐ ํŒจํ„ด

 

์•ˆํ‹ฐ ํŒจํ„ด

์•ˆํ‹ฐํŒจํ„ด(Anti-Pattern)์ด๋ž€ ์†Œํ”„ํŠธ์›จ์–ด ๊ฐœ๋ฐœ, ์„ค๊ณ„, ๋˜๋Š” ๋ฌธ์ œ ํ•ด๊ฒฐ์—์„œ ๋น„ํšจ์œจ์ ์ด๊ณ  ํ•ด๋กœ์šด ๊ด€ํ–‰์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ, ๋น„ํšจ์œจ์ ์ด๊ฑฐ๋‚˜ ๋น„์ƒ์‚ฐ์ ์ผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ์‹๋“ค์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋‹น์‹œ์—๋Š” ๋ฌธ์ œ๊ฐ€ ์—†์–ด๋ณด์ผ ์ˆ˜ ์žˆ์ง€๋งŒ, ์‹œ๊ฐ„์ด ์ง€๋‚˜๊ณ  ์š”๊ตฌ ์‚ฌํ•ญ์ด ๋ฐ”๋€Œ๋ฉด ์ˆ˜์ •์ด ๋งค์šฐ ์–ด๋ ค์›Œ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž˜๋ชป๋œ ๋ฐฉ์‹์œผ๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ๋Š” ์‹คํ–‰ ์†๋„์™€ ์‹œ์Šคํ…œ ์ „์ฒด ์„ฑ๋Šฅ์—๋„ ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค.

 

๋Œ€ํ‘œ์ ์ธ ์•ˆํ‹ฐ ํŒจํ„ด

1. Spaghetti Code (์ŠคํŒŒ๊ฒŒํ‹ฐ ์ฝ”๋“œ)

๊ตฌ์กฐ๊ฐ€ ์—†๋Š” ๋ณต์žกํ•˜๊ณ  ๋’ค์–ฝํžŒ ์ฝ”๋“œ. ์ดํ•ดํ•˜๊ธฐ ์–ด๋ ต๊ณ , ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ๊ฑฐ์˜ ๋ถˆ๊ฐ€๋Šฅํ•˜๊ณ  ์ฝ”๋“œ ๋ณ€๊ฒฝ ์‹œ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๋ฌธ์ œ ๋ฐœ์ƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ

function calculate(value) {
  if (value > 10) {
    if (value < 20) {
      for (let i = 0; i < value; i++) {
        if (i % 2 === 0) {
          // ๋ณต์žกํ•˜๊ณ  ๋น„์ง๊ด€์ ์ธ ๋กœ์ง
        }
      }
    }
  }
}

 

2. God Object (์‹  ๊ฐ์ฒด)

ํ•˜๋‚˜์˜ ๊ฐ์ฒด๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์€ ์ฑ…์ž„์„ ๊ฐ€์ง€๋Š” ์„ค๊ณ„ ๋ฐฉ์‹. ํ•˜๋‚˜์˜ ๊ฐ์ฒด๊ฐ€ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜์—ฌ ์ฝ”๋“œ๊ฐ€ ๋น„ํšจ์œจ์ ์œผ๋กœ ์ž‘๋™. ๋น„ํšจ์œจ์ ์ธ ์œ ์ง€๋ณด์ˆ˜ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

class AppManager {
  constructor() {
    this.user = null;
    this.db = null;
    this.cache = null;
    this.api = null;
  }

  handleAll() {
    // ๋ชจ๋“  ์ผ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฑฐ๋Œ€ํ•œ ๋ฉ”์„œ๋“œ
  }
}

 

3. Golden Hammer (ํ™ฉ๊ธˆ ๋ง์น˜)

ํ•˜๋‚˜์˜ ๋„๊ตฌ(ํ”„๋ ˆ์ž„์›Œํฌ, ๊ธฐ์ˆ )๋ฅผ ๋ชจ๋“  ๋ฌธ์ œ์— ์ ์šฉํ•˜๋ ค๋Š” ๊ฒฝํ–ฅ. ๋ฌธ์ œ์— ๋งž์ง€ ์•Š๋Š” ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋น„ํšจ์œจ์˜ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ

// ๋ชจ๋“  ๋ฌธ์ œ๋ฅผ Regular Expression์œผ๋กœ ํ•ด๊ฒฐํ•˜๋ ค๋Š” ๊ฒฝ์šฐ
const regex = /some-complicated-pattern/;
if (regex.test(input)) {
  // ๋„ˆ๋ฌด ๊ณผ๋„ํ•œ ์ •๊ทœ์‹ ์‚ฌ์šฉ
}

 

4. Hardcoding (ํ•˜๋“œ์ฝ”๋”ฉ)

๊ฐ’์ด๋‚˜ ์„ค์ •์„ ์ฝ”๋“œ์— ์ง์ ‘์ ์œผ๋กœ ํ•˜๋“œ์ฝ”๋”ฉ. ํ™˜๊ฒฝ์ด ๋ณ€๊ฒฝ๋˜๋ฉด ํ•˜๋“œ์ฝ”๋”ฉ๋œ ์—ฌ๋Ÿฌ ๊ตฐ๋ฐ์˜ ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์žฌ์‚ฌ์šฉ์„ฑ๊ณผ ์œ ์ง€๋ณด์ˆ˜์„ฑ์ด ๋‚ฎ์Šต๋‹ˆ๋‹ค.

์˜ˆ์‹œ

const apiUrl = "http://example.com/api/v1"; // ํ•˜๋“œ์ฝ”๋”ฉ๋œ URL

 

5. Premature Optimization (์กฐ๊ธฐ ์ตœ์ ํ™”)

ํ•„์š”ํ•˜์ง€ ์•Š์€ ์ตœ์ ํ™” ์ž‘์—…์— ๋„ˆ๋ฌด ๋งŽ์€ ์‹œ๊ฐ„๊ณผ ์ž์›์„ ์†Œ๋น„. ๋ณต์žก์„ฑ์„ ์ฆ๊ฐ€์‹œํ‚ค๊ณ , ์‹ค์ œ ์ค‘์š”ํ•œ ๋ฌธ์ œ์— ์ง‘์ค‘ํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ์‹œ

function addNumbers(a, b) {
  // ๋‹จ์ˆœํ•œ ์—ฐ์‚ฐ์— ๊ณผ๋„ํ•œ ์ตœ์ ํ™”
  return (a | 0) + (b | 0);
}

 

 

 

6. Singleton Overuse (์‹ฑ๊ธ€ํ†ค ๋‚จ์šฉ)

์‹ฑ๊ธ€ํ†ค ํŒจํ„ด์„ ๊ณผ๋„ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ๋“  ๊ณณ์—์„œ ๊ฐ™์€ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ณต์œ . ํ…Œ์ŠคํŠธํ•˜๊ธฐ ์–ด๋ ค์›Œ์ง€๊ณ , ๋ฌธ์ œ์ƒํ™ฉ์— ๋”ฐ๋ผ ๋™์‹œ์„ฑ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์‹œ

class Database {
  static instance;
  static getInstance() {
    if (!Database.instance) {
      Database.instance = new Database();
    }
    return Database.instance;
  }
}

 


์‹ค๋ฌด์—์„œ ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ์„ฑ๋Šฅ ํ•˜๋ฝ์˜ ์•ˆํ‹ฐ ํŒจํ„ด

 

์œ„ ์˜ˆ์‹œ ์ฒ˜๋Ÿผ ๊ฐ€๋…์„ฑ๊ณผ ์œ ์ง€๋ณด์ˆ˜์„ฑ ์ธก๋ฉด์—์„œ ์•ˆํ‹ฐํŒจํ„ด๋„ ๋งŽ์ง€๋งŒ, ์‹ค๋ฌด์—์„œ ์ž์ฃผ ๋ฐœ์ƒํ•˜๋Š” ์„ฑ๋Šฅ ํ•˜๋ฝ ์ธก๋ฉด์˜ ์•ˆํ‹ฐ ํŒจํ„ด๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

์•ˆํ‹ฐํŒจํ„ด์˜ ์ข…๋ฅ˜๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ์ง€๋งŒ, ์„ฑ๋Šฅ์ ์ธ ๋ฉด(๋ถˆํ•„์š”ํ•œ ์—ฐ์‚ฐ, ๋น„ํšจ์œจ์  ์—ฐ์‚ฐ)์— ์ดˆ์ ์„ ๋งž์ถฐ์„œ ์‚ดํŽด๋ณธ ์œ ํ˜•์ž…๋‹ˆ๋‹ค.

 


์œ ํ˜• 1

๋ถˆํ•„์š”ํ•œ ๋ณ€์ˆ˜ ํ• ๋‹น


AS/IS

const output = someData
return output;


TO/BE

return someData;

 

์œ ํ˜• 2

๋ถˆํ•„์š”ํ•œ ํ”„๋กœํผํ‹ฐ ํ˜ธ์ถœ.

์กฐ๊ฑด๋ฌธ์—์„œ๋„ obj.list.get(key) ์กฐ๊ฑด์„ ๋”ฐ์ง€๋ฉด์„œ .list , get() ํ•จ์ˆ˜๋ฅผ ๋ฃฉ์—…ํ•ด์•ผ ํ•˜๋Š”๋ฐ, ํ•˜๋‚˜์˜ ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ๋‹ค๋ฃจ๋ฉด ๋ถˆํ•„์š”ํ•œ ํ”„๋กœํผํ‹ฐ ํ˜ธ์ถœ์„ ๋ง‰์„ ์ˆ˜ ์žˆ๋‹ค. 

AS/IS

if (obj.list.get(key)) {
	const value = obj.list.get(key)
	console.log(value);
}


TO/BE

const data = obj.list.get(key)
if (data) {	
	console.log(data);
}

 

์œ ํ˜• 3

arr.length ๋ฅผ ๋งค ์ธ๋ฑ์Šค๋งˆ๋‹ค ํ™•์ธํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์€ ์ˆ˜๋ผ๋ฉด ๋ณ€์ˆ˜์— ์„ ์–ธํ•ด๋‘๊ณ  ํ”„๋กœํผํ‹ฐ ํ˜ธ์ถœ ๋ฐ˜๋ณต์„ ๋ง‰์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

AS/IS

for (let i = 0; i < arr.length; i++) {
	console.log(arr[i]);
}

 


TO/BE

const length = arr.length; // ํ”„๋กœํผํ‹ฐ ํ˜ธ์ถœ์„ ๋ฐ˜๋ณตํ•˜์ง€ ์•Š๋„๋ก.
for (let i = 0; i < length; i++) { 
	console.log(arr[i]);
}

 

์œ ํ˜• 4

๋ถ„๊ธฐ๋ฌธ ๋‚จ์šฉ. ๋„ˆ๋ฌด ๋งŽ์€ else if ๋ฌธ์€ ์„ฑ๋Šฅ์˜ ๋ฌธ์ œ์™€ ๊ฐ€๋…์„ฑ์˜ ๋ฌธ์ œ๋ฅผ ์•ผ๊ธฐ์‹œํ‚ต๋‹ˆ๋‹ค. switch ๋ฌธ์„ ํ™œ์šฉํ•œ๋‹ค๋ฉด Lookup Table ๋˜๋Š” Jump Table ์—์„œ ํ•œ๋ฒˆ์— ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋น„์Šทํ•œ ๋ฐฉ์‹์œผ๋กœ Map ์„ ํ™œ์šฉํ•˜๋ฉด ๊ฐ€๋…์„ฑ๊ณผ else if ๋ฅผ ๊ณ„์† ํ™•์ธํ•˜๋Š” ์„ฑ๋Šฅ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


AS/IS

function getLocalizedErrorMessage(errorCode: number, language: string): string {
  if (language === "en") {
    if (errorCode === 400) {
      return "Bad Request";
    } else if (errorCode === 401) {
      return "Unauthorized";
    } else if (errorCode === 404) {
      return "Not Found";
    } else {
      return "Unknown Error";
    }
  } else if (language === "ko") {
    if (errorCode === 400) {
      return "์ž˜๋ชป๋œ ์š”์ฒญ";
    } else if (errorCode === 401) {
      return "์ธ์ฆ๋˜์ง€ ์•Š์Œ";
    } else if (errorCode === 404) {
      return "์ฐพ์„ ์ˆ˜ ์—†์Œ";
    } else {
      return "์•Œ ์ˆ˜ ์—†๋Š” ์˜ค๋ฅ˜";
    }
  } else {
    return "Unknown Error"; // ์ง€์›๋˜์ง€ ์•Š๋Š” ์–ธ์–ด
  }
}



TO/BE

const localizedErrorMessages: Map<string, Map<number, string>> = {
  en: {
    400: "Bad Request",
    401: "Unauthorized",
    404: "Not Found",
  },
  ko: {
    400: "์ž˜๋ชป๋œ ์š”์ฒญ",
    401: "์ธ์ฆ๋˜์ง€ ์•Š์Œ",
    404: "์ฐพ์„ ์ˆ˜ ์—†์Œ",
  },
};

function getLocalizedErrorMessage(errorCode: number, language: string): string {
  return localizedErrorMessages[language]?.[errorCode] ?? "Unknown Error";
}

 

์œ ํ˜• 5

๋ถˆํ•„์š”ํ•œ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ.

execute({}); ์—์„œ ๋ถˆํ•„์š”ํ•˜๊ฒŒ {}๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ธ์Šคํ„ด์Šค๋Š” heap ์˜์—ญ์— ๋กœ๋“œ๋˜๊ณ , GC ์— ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค. GC ํ™œ๋™ ์ž์ฒด๋„ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ๋ถˆํ•„์š”ํ•œ ์ธ์Šคํ„ด์Šค๋ฅผ ๋˜๋„๋ก ์ƒ์„ฑํ•˜์ง€ ์•Š๋Š” ๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค.

 

AS/IS

interface IStateRequest {
	info_list?: InfoListType[];
}

// ----

const state_program = ProgramBuilder.create<IStateRequest, void>(
    IStateProgram,
    execution_context
);

const { group_data } = state_program.execute({});



TO/BE

type RequestType = IStateRequest | undefined;

const { group_data } = state_program.execute(); // ์œ ๋‹ˆ์˜จํƒ€์ž…์„ ํ™œ์šฉํ•˜์—ฌ, ๋ถˆํ•„์š”ํ•œ ๊ฐ์ฒด์ธ์Šคํ„ด์Šค ์ƒ์„ฑ ๋ฐฉ์ง€

 

์œ ํ˜• 6

๋ถˆํ•„์š”ํ•œ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ.

let resultItemJson: any = {}; ์—์„œ ์„ ์–ธ๋งŒ ํ•ด๋„ ๋˜๋Š”๋ฐ, ๋ถˆํ•„์š”ํ•œ ๋นˆ ๊ฐ์ฒด๋ฅผ ํ• ๋‹นํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๋˜ํ•œ else ์—์„œ๋„ ๋ถˆํ•„์š”ํ•œ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ณ„์† ์ƒ์„ฑํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

AS/IS

let resultItemJson: any = {};
if (state.attribute_set_sid) {
    resultItemJson = JSON.parse(state.result_item_json);
} else {
    resultItemJson = {
        option_one: '0',
        option_two: '0',
        option_three: '0',
        sequence_one: '1',
        sequence_two: '2',
        sequence_three: '3',
    };
}



TO/BE

const default_result = { // ์‹ฑ๊ธ€ํ†ค ๊ฐ์ฒด
    option_one: '0',
    option_two: '0',
    option_three: '0',
    sequence_one: '1',
    sequence_two: '2',
    sequence_three: '3',
};

let resultItemJson: any; // ๋ณ€์ˆ˜ ์„ ์–ธ๋งŒ
if (state.attribute_set_sid) {
    resultItemJson = JSON.parse(state.result_item_json);
} else {
    resultItemJson = default_result; // ์‹ฑ๊ธ€ํ†ค ๊ฐ์ฒด ์žฌํ™œ์šฉ (์™ธ๋ถ€ ์ˆ˜์ • ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด Object.freeze ๊ณ ๋ ค ๊ฐ€๋Šฅ)
}

 

์œ ํ˜• 7

๋ถ€์ ์ ˆํ•œ ์ž๋ฃŒ ๊ตฌ์กฐ ํ™œ์šฉ.

์ „์ž์˜ ๊ฒฝ์šฐ ๋ฐฐ์—ด์„ ํ†ตํ•ด ์›ํ•˜๋Š” ๊ฐ’์„ ์ฐพ๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์ด๋Š” O(N) ์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ Set ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ํ™œ์šฉํ•˜๊ฒŒ ๋œ๋‹ค๋ฉด ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ๋”์šฑ ๋น ๋ฅด๊ฒŒ ์›ํ•˜๋Š” ๊ฐ’์„ ํƒ์ƒ‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

AS/IS

function isAllowed(value: string): boolean {
  const allowedValues = ["apple", "banana", "cherry", "date", "elderberry"];
  return allowedValues.includes(value);
}



TO/BE

const allowedValues = new Set(["apple", "banana", "cherry", "date", "elderberry"]);

function isAllowed(value: string): boolean {  
  return allowedValues.has(value);
}

 

์œ ํ˜• 8

๋ถ€์ ์ ˆํ•œ ํ•จ์ˆ˜ ์‚ฌ์šฉ.

forEach ํ•จ์ˆ˜๋Š” ๋‚ด๋ถ€์ ์œผ๋กœ Iterator ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ ๋ฐ›์•„ ๋ฐ˜๋ณต๋ฌธ์„ ๋Œ๋ฆฌ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. Iterator ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ๋ถ€ํ„ฐ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค. forEach๋Š” ๋ฐฐ์—ด์˜ ๊ฐ ์š”์†Œ๋งˆ๋‹ค ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ํ•จ์ˆ˜ ํ˜ธ์ถœ์—๋Š” ์Šคํƒ ํ”„๋ ˆ์ž„ ์ƒ์„ฑ ๋ฐ ํ•ด์ œ ๋“ฑ์˜ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ for๋ณด๋‹ค ๋А๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

map ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ผ๋ฐ˜์ ์ธ ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•˜๋ฉด์„œ ๋ฐฐ์—ด์— ์ง์ ‘์ ์œผ๋กœ push ํ•˜๊ณ  ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•ด์ค๋‹ˆ๋‹ค. ์ด๋Š” forEach ๋ฅผ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์„ฑ๋Šฅ๋ฉด์—์„œ ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค.

AS/IS

 

const { source_list } = example_program.execute(request);
const result_list = [];

source_list.forEach((source) => {
        result_list.push({
            tenant_sid: source.com_code,
            name: source.nm,
        });
});




TO/BE

const { source_list } = example_program.execute(request);
const result_list = source_list.map((source) => {
        return {
            tenant_sid: source.com_code,
            name: source.nm,
        }
});

 

์œ ํ˜• 9

๋น„ํšจ์œจ์ ์ธ ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ.

๋ฌธ์ž์—ด์„ ๊ฒฐํ•ฉํ•  ๋•Œ + ์—ฐ์‚ฐ์ž๋ฅผ ํ™œ์šฉํ•˜๊ฒŒ ๋˜๋ฉด StringBuilder ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์—ฐ์‚ฐํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ๋” ๋†’์€ ์˜ค๋ฒ„ํ—ค๋“œ์™€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. 


AS/IS

for (let j = 1; j <= 70; j++) {
    console.log("column" + j);
}



TO/BE

for (let j = 1; j <= 70; j++) {
    console.log(`column${j}`);
}

 


์•ˆํ‹ฐํŒจํ„ด์„ ํ”ผํ•˜๋Š” ๋ฐฉ๋ฒ•

  1. SOLID ์›์น™ ์ค€์ˆ˜
    • ๊ฐ์ฒด ์ง€ํ–ฅ ์„ค๊ณ„ ์›์น™(SOLID)์„ ๋”ฐ๋ฅด๋ฉด, ์ฝ”๋“œ ์œ ์ง€๋ณด์ˆ˜์„ฑ๊ณผ ์žฌ์‚ฌ์šฉ์„ฑ์ด ๋†’์•„์ง€๊ณ  ์•ˆํ‹ฐํŒจํ„ด์„ ํ”ผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  2. ์ฝ”๋“œ ๋ฆฌ๋ทฐ
    • ํŒ€์›๋“ค๊ณผ ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ํ†ตํ•ด ์„ค๊ณ„๋‚˜ ๊ตฌํ˜„ ์ƒ์˜ ๋ฌธ์ œ์ ์„ ์‚ฌ์ „์— ๋ฐœ๊ฒฌ.
  3. ํ…Œ์ŠคํŠธ ์ž‘์„ฑ
    • ์ฝ”๋“œ๊ฐ€ ํŠน์ • ์ƒํ™ฉ์—์„œ ์˜ˆ์ƒ๋Œ€๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋ฉฐ ์•ˆํ‹ฐํŒจํ„ด ๋ฐœ์ƒ ๋ฐฉ์ง€.
  4. ๊ธฐ์ˆ  ์ดํ•ด ์‹ฌํ™”
    • ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ์ˆ ์˜ ์žฅ๋‹จ์ ์„ ๊นŠ์ด ์ดํ•ดํ•˜๊ณ  ์ ์ ˆํžˆ ์ ์šฉ.
  5. ์œ ์—ฐ์„ฑ ํ™•๋ณด
    • ํ•˜๋“œ์ฝ”๋”ฉ ๋Œ€์‹  ํ™˜๊ฒฝ ๋ณ€์ˆ˜, ์„ค์ • ํŒŒ์ผ ๋“ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ์œ ์—ฐ์„ฑ์„ ์œ ์ง€.

๋Œ“๊ธ€