[weekly] [nb] 프레임워크와 라이브러리
프레임워크와 라이브러리의 차이에 대해 설명해 주세요.
프레임워크 vs 라이브러리
항목 | 프레임워크 | 라이브러리 |
---|---|---|
역할 | 펠트 인형 만들기 키트 | 펠트 원단, 실, 바늘, 단추, 솜 등 |
제어권 | 정해진 설계도와 절차 | 자유 |
유연성 | 낮음(안정성) | 높음(창의적) |
예시 | express.js | http |
프레임워크
import { createDollKit, defineStyle, decorateFace } from 'felt-kit';
// 1. 키트를 생성하고 기본 구성 선택
const kit = createDollKit({
model: 'teddy',
color: 'brown',
size: 'medium',
});
// 2. 사용자 정의 부분만 제공: 바느질 스타일, 장식 등
defineStyle(kit, {
stitch: 'whipstitch',
thread: 'brown',
});
decorateFace(kit, {
eyes: 'button',
mouth: 'smile',
cheeks: 'blush',
});
// 3. 키트가 전체 인형 제작을 자동으로 수행
kit.build().then((doll) => {
console.log('인형 완성', doll);
});
라이브러리
import pelt from 'pelt'; // 펠트 원단 자르기 도구
import needle from 'needle'; // 바느질 도구
import fill from 'fluff-filler'; // 솜 채우는 도구
import decorate from 'bead-glue'; // 단추나 장식 붙이기 도구
// 1. 펠트를 자른다
const pieces = pelt.cut('teddy', {
head: { shape: 'circle', size: 10 },
body: { shape: 'oval', size: 20 },
arms: { shape: 'rectangle', size: 5 },
});
// 2. 바느질로 조립한다
const stitched = needle.sew(pieces, {
thread: 'brown',
style: 'whipstitch',
});
// 3. 솜을 넣는다
const filled = fill(stitched, { fluff: 'polyester' });
// 4. 장식을 붙인다
const finished = decorate(filled, {
eyes: 'button',
smile: 'red-thread',
});
console.log('인형 완성', finished);