์ „์ฒด ๊ธ€

Map ์„ ์–ธ๊ณผ ๋™์‹œ์— ์ดˆ๊ธฐํ™” ํ•˜๋Š” ๋ฐฉ๋ฒ• Map map = new HashMap() { { put("key1", "value1"); put("key2", "value2"); } }; Map map2 = Map.ofEntries( entry("key1", "value1"), entry("key2", "value2"), entry("key3", "value3")); Map.getOrDefault System.out.println(map2.getOrDefault("Key9999", "key not found")); // key not found ๐Ÿ‘ Reference ๋”๋ณด๊ธฐ https://devfunny.tistory.com/465
์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class); ApplicationContext๋ฅผ ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๋ผ ํ•œ๋‹ค. ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๋Š” @Configuration์ด ๋ถ™์€ AppConfig๋ฅผ ์„ค์ •์ •๋ณด๋กœ ์‚ฌ์šฉํ•œ๋‹ค. ์—ฌ๊ธฐ์„œ @Bean์ด๋ผ ์ ํžŒ ๋ฉ”์„œ๋“œ๋ฅผ ๋ชจ๋‘ ํ˜ธ์ถœํ•ด์„œ ๋ฐ˜ํ™˜๋œ ๊ฐ์ฒด๋ฅผ ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์— ๋“ฑ๋กํ•œ๋‹ค. ์ด๋ ‡๊ฒŒ ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์— ๋“ฑ๋ก๋œ ๊ฐ์ฒด๋ฅผ ์Šคํ”„๋ง ๋นˆ์ด๋ผ๊ณ  ํ•œ๋‹ค. ์Šคํ”„๋ง ๋นˆ์€ @Bean์ด ๋ถ™์€ ๋ฉ”์„œ๋“œ์˜ ๋ช…์„ ์Šคํ”„๋ง ๋นˆ์˜ ์ด๋ฆ„์œผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค ์Šคํ”„๋ง ๋นˆ์€ applicationContext.getBean() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ๋Š” XML ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค ์ˆ˜..
1๏ธโƒฃ ์ œ์–ด์˜ ์—ญ์ „ IoC, Inversion of Control ๊ธฐ์กด ํ”„๋กœ๊ทธ๋žจ์€ ํด๋ผ์ด์–ธํŠธ ๊ตฌํ˜„ ๊ฐ์ฒด๊ฐ€ ์Šค์Šค๋กœ ํ•„์š”ํ•œ ์„œ๋ฒ„ ๊ตฌํ˜„ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ (new๋กœ ์ง์ ‘ ์ƒ์„ฑ), ์—ฐ๊ฒฐํ•˜๊ณ , ์‹คํ–‰ํ–ˆ๋‹ค. ๋ฐ˜๋ฉด์— AppConfig๊ฐ€ ๋“ฑ์žฅํ•œ ์ดํ›„์— ๊ตฌํ˜„ ๊ฐ์ฒด๋Š” ์ž์‹ ์˜ ๋กœ์ง์„ ์‹คํ–‰ํ•˜๋Š” ์—ญํ• ๋งŒ ๋‹ด๋‹นํ•œ๋‹ค. ํ”„๋กœ๊ทธ๋žจ์˜ ์ œ์–ด ํ๋ฆ„์„ AppConfig๊ฐ€ ๊ฐ€์ ธ๊ฐ„ ๊ฒƒ์ด๋‹ค. ํด๋ผ์ด์–ธํŠธ ๊ฐ์ฒด๋Š” ํ•„์š”ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋“ค์„ ํ˜ธ์ถœํ•˜์ง€๋งŒ ์–ด๋–ค ๊ตฌํ˜„ ๊ฐ์ฒด๊ฐ€ ์‹คํ–‰๋ ์ง€๋Š” ๋ชจ๋ฅธ๋‹ค. ํ”„๋กœ๊ทธ๋žจ์— ๋Œ€ํ•œ ์ œ์–ด ํ๋ฆ„์€ ๋ชจ๋‘ AppConfig๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๊ฒŒ ๋œ๋‹ค. ์ด๋ ‡๋“ฏ ํ”„๋กœ๊ทธ๋žจ์˜ ์ œ์–ด ํ๋ฆ„์„ ์ง์ ‘ ์ œ์–ดํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ์™ธ๋ถ€์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์„ ์ œ์–ด์˜ ์—ญ์ „์ด๋ผ ํ•œ๋‹ค. This chapter covers the Spring Framework implementation o..
SOLID, ์ข‹์€ ๊ฐ์ฒด ์ง€ํ–ฅ ์„ค๊ณ„์˜ 5๊ฐ€์ง€ ์›์น™ ํด๋ฆฐ์ฝ”๋“œ๋กœ ์œ ๋ช…ํ•œ ๋กœ๋ฒ„ํŠธ ๋งˆํ‹ด์ด ์ข‹์€ ๊ฐ์ฒด ์ง€ํ–ฅ ์„ค๊ณ„์˜ 5๊ฐ€์ง€ ์›์น™์„ ์ •๋ฆฌ Martin and Feathers' design principles encourage us to create more maintainable, understandable, and flexible software. Martin๊ณผ Feather์˜ SOLID ์›์น™์€ ์ข€ ๋” ์œ ์ง€ ๊ด€๋ฆฌํ•˜๊ธฐ ์‰ฝ๊ณ  ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์šฐ๋ฉฐ ์œ ์—ฐํ•œ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๋งŒ๋“ค๋„๋ก ๋„์™€์ค€๋‹ค. ๋‹จ์ผ ์ฑ…์ž„ ์›์น™ SRP, Single responsibility principle ํ•œ ํด๋ž˜์Šค๋Š” ํ•˜๋‚˜์˜ ์ฑ…์ž„๋งŒ ๊ฐ€์ ธ์•ผ ํ•œ๋‹ค. ํ•˜๋‚˜์˜ ์ฑ…์ž„์ด๋ผ๋Š” ๊ฒƒ์€ ๋ชจํ˜ธํ•˜๋‹ค. ์ค‘์š”ํ•œ ๊ธฐ์ค€์€ ๋ณ€๊ฒฝ์ด ์žˆ์„ ๋•Œ ํŒŒ๊ธ‰ ํšจ๊ณผ๊ฐ€ ์ ์œผ๋ฉด ๋‹จ์ผ ์ฑ…์ž„ ์›์น™์„ ์ž˜ ๋”ฐ๋ฅธ ๊ฒƒ์ด๋‹ค. ..
String ๋ณ€์ˆ˜๊ฐ€ Null์ผ ๋•Œ "" ์–ป๋Š” ๋ฐฉ๋ฒ• ์ฐจ์„ธ๋Œ€ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉฐ, ๋ฉ”์„œ๋“œ๋‚ด์˜ String ๋ณ€์ˆ˜๊ฐ€ ๋ฌด์กฐ๊ฑด Null์ด ์•„๋‹Œ ๊ฐ’์ด ๋“ค์–ด์˜จ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์ง€๋งŒ ์•„๋‹Œ ๊ฒฝ์šฐ๊ฐ€ ๋‹ค์ˆ˜ ๋ฐœ์ƒํ•ด์„œ ์•Œ์•„๋ณด๊ฒŒ ๋˜์—ˆ๋‹ค. ๋“ค์–ด์˜ฌ ์ˆ˜ ์žˆ๋Š” input ๋ฒ”์œ„๋ฅผ ์•Œ๊ณ  ๊ฐœ๋ฐœํ•˜๋ฉด ์ข‹๊ฒ ์ง€๋งŒ ๊ทธ๋Ÿฌ์ง€ ๋ชปํ•˜๋Š” ์ƒํ™ฉ์ด๋ผ ์ž„์‹œ ๋ฐฉ์•ˆ์œผ๋กœ NullPointException์„ ๋ง‰๊ธฐ ์œ„ํ•ด ๋กœ์ง๋‚ด์— ์ถ”๊ฐ€ํ–ˆ๋‹ค. // standard in Java 7 String nullString = null; String emptyString = Objects.toString(nullString, ""); // In Java 9+. returns empty string if obj is null Objects.requireNonNullElse (nullString, ..
YURI๐Ÿ•๐Ÿ“๐Ÿถ
๐Ÿ•