TURI BLOG

[Nomad Coders Challenge] Clean Code - Assignment #08 ๋ณธ๋ฌธ

Nomad Coders

[Nomad Coders Challenge] Clean Code - Assignment #08

TURI BLOG 2024. 12. 8. 11:20

 

 

๐Ÿ“ It is part of a book club challenge on a programming learning website called Nomad Coders. The challenge is to demonstrate what I have learned after reading Clean Code by Robert C. Martin.

 

๐Ÿ“ It will consist of the following sections over three weeks: the range of reading, the top quotes from the book, my review, and remaining questions. 

  ๐Ÿ”—Challenge Schedule


๐Ÿ’ป I plan to read Clean Code in JavaScript and Python, referring to the GitHub repositories shared by Nomad Coders with the challengers.

 

Assignment #08

  • ๐Ÿ“š Chapter 6. Objects and Data Structures 
  • โœ”๏ธ TIL 
    • Top quotes from the book
    • Remaining questions

 

๐Ÿ“ Top quotes from the book

 

  • Law of Demeter (๋””๋ฏธํ„ฐ ๋ฒ•์น™) :  ๋ฌ˜๋“ˆ์€ ์ž์‹ ์ด ์กฐ์ž‘ํ•˜๋Š” ๊ฐ์ฒด์˜ ์†์‚ฌ์ •์„ ๋ชฐ๋ผ์•ผ ํ•œ๋‹ค๋Š” ๋ฒ•์น™ 
    • ๋‚ด๋ถ€ ๊ตฌ์กฐ๋ฅผ ์ˆจ๊ธฐ์ง€ ์•Š๊ณ  ๋…ธ์ถœํ•˜๋Š” ์…ˆ์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์—, ๊ฐ์ฒด๋Š” ์กฐํšŒ ํ•จ์ˆ˜๋กœ ๋‚ด๋ถ€ ๊ตฌ์กฐ๋ฅผ ๊ณต๊ฐœํ•˜๋ฉด ์•ˆ ๋œ๋‹ค๋Š” ์˜๋ฏธ๋‹ค. 
    • train wreck
      • This code violates the Law of Demeter by chaining multiple method calls.
        // BAD โ›”
        // Found in Apache code
        final String outputDir = ctxt.getOptions().getScratchDir().getAbsolutePath();
        
        // GOOD ๐Ÿ˜Ž
        Options opts = ctxt.getOptions();
        File scratchDir = opts.getScratchDir();
        final String outputDir = scratchDir.getAbsolutePath();
       
  • ์ž๋ฃŒ ์ „๋‹ฌ ๊ฐ์ฒด
    • ์ž๋ฃŒ๊ตฌ์กฐ์ฒด์˜ ์ „ํ˜•์ ์ธ ํ˜•ํƒœ๋Š” ๊ณต๊ฐœ ๋ณ€์ˆ˜๋งŒ ์žˆ๊ณ  ํ•จ์ˆ˜๊ฐ€ ์—†๋Š” ํด๋ž˜์Šค - ์ž๋ฃŒ ์ „๋‹ฌ ๊ฐ์ฒด(Data Transfer Object, DTO). ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ํ†ต์‹ ํ•˜๊ฑฐ๋‚˜ ์†Œ์ผ“์—์„œ ๋ฐ›์€ ๋ฉ”์„ธ์ง€์˜ ๊ตฌ๋ฌธ์„ ๋ถ„์„ํ•  ๋•Œ ์œ ์šฉํ•˜๋‹ค. ํ”ํžˆ DTO๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋œ ๊ฐ€๊ณต๋˜์ง€ ์•Š์€ ์ •๋ณด๋ฅผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฝ”๋“œ์—์„œ ์‚ฌ์šฉํ•  ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ์ผ๋ จ์˜ ๋‹จ๊ณ„์—์„œ ๊ฐ€์žฅ ์ฒ˜์Œ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ตฌ์กฐ์ฒด๋‹ค. 

 

 

 

 

๐Ÿ” Remaining questions

  • Law of Demeter

  • DTO(Data Transfer Object)
  • Object Oriented Programming(๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ)
  • Procedural Programming(์ ˆ์ฐจ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ)

 


๐Ÿ”— Additional Resources

Comments