๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[ํ”„๋กœ๊ทธ๋ž˜๋ฐ] ๋ฉ”์„œ๋“œ ์ถ”์ถœ ๋ฆฌํŒฉํ† ๋ง Extract Method

์ถœ์ฒ˜

https://zaengle.com/blog/refactoring-techniques-extract-method

 

Refactoring Techniques: Extract Method | Zaengle Corp

Insights on refactoring techniques focusing on the extract method and Martin Fowlers's book Refactoring - Improving the Design of Existing Code.

zaengle.com

https://hceris.com/the-humble-extract-method/

 

The Humble Extract Method

The extract method refactoring is a low-cost, high-impact tool to increase maintainability in your code. Let's talk about its benefits

hceris.com

https://refactoring.guru/extract-method

 

Extract Method

Tired of reading? No wonder, it takes 7 hours to read all of the text we have here. Try our interactive course on refactoring. It offers a less tedious approach to learning new stuff. Let's see…

refactoring.guru

ChatGPT

 


๋ฉ”์„œ๋“œ ์ถ”์ถœ ๋ฆฌํŒฉํ† ๋ง Mehtod Extraction Refactoring

ํŠน์ • ๋ฉ”์„œ๋“œ ์•ˆ์˜ ์ฝ”๋“œ๋“ค์„ ๋” ์ž‘์€ ๋…๋ฆฝ๋œ ๋ฉ”์„œ๋“œ๋กœ ์ชผ๊ฐœ์„œ ๋ถ„๋ฆฌํ•˜๋Š” ๋ฆฌํŒฉํ† ๋ง ๊ธฐ๋ฒ•. ์ž‘์€ ๋ณด์กฐ ๋ฉ”์„œ๋“œ๋“ค์€ ์ด ๋ฉ”์„œ๋“œ์˜ ๋ชฉ์ ์„ ์„ค๋ช…ํ•˜๋Š” ์ด๋ฆ„์„ ๊ฐ–๋Š”๋‹ค.

 

์žฅ์ 

๊ฐ€๋…์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚จ๋‹ค.

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

์ค‘๋ณต์ด ์ค„๊ณ  ์žฌ์‚ฌ์šฉ์„ฑ์ด ์ฆ๊ฐ€ํ•œ๋‹ค.

  • ์ชผ๊ฐ  ๋ฉ”์„œ๋“œ๋ฅผ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
    • ๊ทธ๋ ‡์ง€๋งŒ ์žฌ์‚ฌ์šฉ ์ž์ฒด๊ฐ€ ๋ฉ”์„œ๋“œ ์ถ”์ถœ ๋ฆฌํŒฉํ† ๋ง์˜ ๋ชฉ์ ์€ ์•„๋‹ˆ๋‹ค. ์งง์€ ๋ณด์กฐ ๋ฉ”์„œ๋“œ๊ฐ€ ํ•œ ๋ฒˆ๋งŒ ์“ฐ์ด๋”๋ผ๋„ ๊ฐ€๋…์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚จ๋‹ค๋ฉด ์กด์žฌ์˜ ์˜๋ฏธ๊ฐ€ ์žˆ๋‹ค.

ํ…Œ์ŠคํŠธ๊ฐ€ ์šฉ์ดํ•˜๋‹ค.

  • ์ถ”์ถœ๋œ ๋ฉ”์„œ๋“œ๋Š” ๊ฐœ๋ณ„์ ์œผ๋กœ ํ…Œ์ŠคํŠธ ๊ฐ€๋Šฅํ•˜๋‹ค. ์ž‘์€ ๋‹จ์œ„์˜ ๋ฉ”์„œ๋“œ๋Š” ํ…Œ์Šคํฌ๊ฐ€ ์‰ฝ๊ณ  ๊ฐ ๊ธฐ๋Šฅ์„ ๋…๋ฆฝ์ ์œผ๋กœ ๊ฒ€์ฆํ•  ์ˆ˜ ์žˆ์–ด ์ฝ”๋“œ ํ’ˆ์งˆ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.

 

๋ฉ”์„œ๋“œ ์ถ”์ถœ ๋ฆฌํŒฉํ† ๋ง์˜ ๋‹จ๊ณ„

1. ์ถ”์ถœํ•  ์ฝ”๋“œ ์‹๋ณ„

๋ฐ˜๋ณต์ ์ด๊ฑฐ๋‚˜ ๋ณต์žกํ•œ ์ฝ”๋“œ ๋ธ”๋ก์„ ์ฐพ๋Š”๋‹ค.

2. ์ƒˆ ๋ฉ”์„œ๋“œ ์ž‘์„ฑ

์ถ”์ถœํ•  ์ฝ”๋“œ ๋ธ”๋ก์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒˆ ๋ฉ”์„œ๋“œ๋ฅผ ์ •์˜ํ•˜๊ณ , ๋ชฉ์ ์„ ์„ค๋ช…ํ•˜๋Š” ์ด๋ฆ„์„ ๋ถ€์—ฌํ•œ๋‹ค.

3. ๋งค๊ฐœ๋ณ€์ˆ˜ ์ฒ˜๋ฆฌ

์ถ”์ถœ๋œ ์ฝ”๋“œ๊ฐ€ ์‚ฌ์šฉํ•œ ๋ณ€์ˆ˜๋ฅผ ์ ์ ˆํžˆ ๋ฉ”์„œ๋“œ์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌํ•œ๋‹ค.

4. ๊ธฐ์กด ์ฝ”๋“œ ๋Œ€์ฒด

์›๋ž˜ ์ฝ”๋“œ ๋ธ”๋ก์„ ์ƒˆ ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ๋กœ ๋Œ€์ฒดํ•œ๋‹ค.

5. ํ…Œ์ŠคํŠธ

๋ฆฌํŒฉํ† ๋ง ํ›„ ๊ธฐ์กด ์ฝ”๋“œ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•œ๋‹ค.

 

์ถ”์ถœํ•œ ๋ฉ”์„œ๋“œ ์ด๋ฆ„ ์ง“๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค๋ฉด

1) ๋ถˆ๋ถ„๋ช…ํ•œ ๊ฒฝ๊ณ„์™€ ๋ชจํ˜ธํ•œ ์ฑ…์ž„์„ ๊ฐ€์ง„ ๋ฉ”์„œ๋“œ์ผ ์ˆ˜ ์žˆ๋‹ค. 

2) ๋ฉ”์„œ๋“œ๊ฐ€ ์—ฌ์ „ํžˆ ๋„ˆ๋ฌด ์ปค์„œ ๋” ๋ถ„ํ• ํ•ด์•ผ ํ•œ๋‹ค.