Design Patterns with Javascript
Design patterns makes code short, less bugs, maintainable, re-usable and scalable
์ ์ฅ์ ์๋ ๋ถ๊ตฌํ๊ณ ์ฃผ์ํด์ ์ฌ์ฉํ์ง ์์ผ๋ฉด ์ ์ฅ์ ์ด ์ ๋ถ ๋ฐ๋๊ฐ ๋์ด๋ฒ๋ฆด ์ ์๋ค. ๊ฐ ํจํด์ ๋ํ ํน์ฑ์ ์ ํํ ํ์ ํ๊ณ ์ ์ ํ ๊ณณ์ ํ์ฉ ํ ์ค ์์์ผ ๋์์ธ ํจํด์ ์ฌ์ฉํจ์ผ๋ก ์ธํ ์ฅ์ ์ ๊ทน๋ํ ํ ์ ์์ผ๋ฏ๋ก ๋์์ธ ํจํด๋ง์ ์ํ ์ฝ๋๋ฅผ ์์ฑํ๋๊ฒ์ ์กฐ์ฌํ์.
Keep it simple and stupid ์์น์ ์๊ธฐํ๋ฉด์ ๋์์ธ ํจํด์ ํ์ฉํ์.
Null object pattern
Null safety ๋ฅผ ์ํ ํจํด. ํจ์๋ ๋ฉ์๋์์ ๋ฆฌํดํ๋ ๊ฐ์ฒด๊ฐ nullable ํ ๊ฒฝ์ฐ null ๋์ null object ๋ฅผ ๋ฐํํ์ฌ runtime error ์ ๋ฐฉ์งํ๊ณ ์ฝ๋๋ฅผ ๊น๋ํ๊ฒ ์์ฑํ์.
Builder Pattern
Builder ํด๋์ค๋ฅผ ์์ฑํ๊ฑฐ๋ ์์ฑ์์์ optional ํ๋ผ๋ฏธํฐ๋ ๊ฐ์ฒด๋ก ๋ฐ๊ณ , default ๊ฐ์ ํ์ฉํ์ฌ ์ฝ๋๋ฅผ ๊ฐ๊ฒฐํ๊ฒ ๋ง๋ค์.
e.g)
class User {
constructor(name, { age, address = 'seoul', email} = {}) {
this.name = name
this.age = age
this.address = address
this.email = email
}
}
const user = new User('Sam', {age: 30, email: 'hellosam1332@gmail.com'})
console.log(user) // User {name: "Sam", age: 30, address: "seoul", email: "hellosam1332@gmail.com"}
Facade pattern
The idea of the facade pattern is to create your own API that hides away complex or repetitive code so that you are left with a clean and easy to use API. The benefits of this is not only clean code that is easy and fun to work with, but your code is also much easier to refactor when the complex code behind your facade needs to change.
Command Pattern
The idea of the command pattern is to create an abstraction between the operations an object can do, its commands, and the actual commands themselves. This makes it really easy to combine together or chain different commands without having to change the code. The program can dynamically chain and combine these actions. The best part is since each command is its own object you can easily implement and undo function for each command and make a set of undo-able actions.
Reference
https://www.youtube.com/watch?v=BWprw8UHIzA&list=PLZlA0Gpn_vH_CthENcPCM0Dww6a5XYC7f
Author And Source
์ด ๋ฌธ์ ์ ๊ดํ์ฌ(Design Patterns with Javascript), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://velog.io/@hellosam/Design-Patterns-with-Javascript์ ์ ๊ท์: ์์์ ์ ๋ณด๊ฐ ์์์ URL์ ํฌํจ๋์ด ์์ผ๋ฉฐ ์ ์๊ถ์ ์์์ ์์ ์ ๋๋ค.
์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ
์ธ ๋ฐ๊ฒฌ์ ์ ๋
(Collection and Share based on the CC Protocol.)
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค