let Rectangle = { resizeTopLeft(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeTopRight(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeBottomLeft(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeBottomRight(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math },};let Oval = { resizeLeft(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeRight(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeTop(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeBottom(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math },};let Header = { resizeLeft(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeRight(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, }let TextBlock = { resizeTopLeft(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeTopRight(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeBottomLeft(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math }, resizeBottomRight(position, size, preserveAspect, dx, dy) { // 10 repetitive lines of math },};Oval.resizeLeft()는 Header.resizeLeft()와 유사성이 있었습니다. 이는 둘 다 왼쪽 핸들을 드래그하는 것을 다루었기 때문입니다.Oval.resizeLeft()는 다른 Oval 메서드들과 유사성이 있었습니다. 이는 모두 타원을 다루었기 때문입니다. Rectangle, Header, TextBlock 간에도 중복이 있었는데, 텍스트 블록이 직사각형이었기 때문입니다.let Directions = { top(...) { // 5 unique lines of math }, left(...) { // 5 unique lines of math }, bottom(...) { // 5 unique lines of math }, right(...) { // 5 unique lines of math },};let Shapes = { Oval(...) { // 5 unique lines of math }, Rectangle(...) { // 5 unique lines of math },}let {top, bottom, left, right} = Directions;function createHandle(directions) { // 20 lines of code}let fourCorners = [ createHandle([top, left]), createHandle([top, right]), createHandle([bottom, left]), createHandle([bottom, right]),];let fourSides = [ createHandle([top]), createHandle([left]), createHandle([right]), createHandle([bottom]),];let twoSides = [ createHandle([left]), createHandle([right]),];function createBox(shape, handles) { // 20 lines of code}let Rectangle = createBox(Shapes.Rectangle, fourCorners);let Oval = createBox(Shapes.Oval, fourSides);let Header = createBox(Shapes.Rectangle, twoSides);let TextBox = createBox(Shapes.Rectangle, fourCorners);아직 댓글이 없습니다.
첫 번째 댓글을 작성해보세요!

React와 Remix가 선택한 서로 다른 미래
Inkyu Oh • Front-End

환영합니다!
Inkyu Oh • 공지사항

setState는 어떻게 무엇을 해야 할지 알까?
Inkyu Oh • Front-End

"Bug-O" 표기법
Inkyu Oh • Front-End