Giter Club home page Giter Club logo

anocat's Issues

[리팩터] 분기문 쓰지말고 다형성 쓰세요

anocat/src/anocat.js

Lines 18 to 30 in a90e1f0

static useLayout(layout, reference = 'div.another_category') {
let decorator;
switch (layout) {
case 'card-vertical':
decorator = new _VerticalCardViewConfigHolder().getDecorator();
break;
case 'card-horizontal':
decorator = new _HorizontalCardViewConfigHolder().getDecorator();
break;
case 'test':
default:
decorator = new _TestViewConfigHolder().getDecorator();
}

[이슈 내용]
분기구문을 사용하나, 분기 처리는 동일한 코드 반복함.

[해결 방안]
레이아웃 이름을 키로 하여 O(n) 짜리 검색으로
원하는 홀더를 획득하도록 하자.
획득한 홀더의 getDecorator 호출하면 끝.
그러기 위해 홀더 클래스 작성 시 name 속성을 부여 하자.

[AnocatPost] 싱글톤 패턴: 다른 카테고리 글 목록을 보유하는 클래스를 사용합시다

[개선사항]
AnocatDecorator 객체를 생성할 때 마다, AnocatReference를 획득하고 Posts 객체를 작성하는 중이다.

  • 하지만 Posts 객체는 해당 블로그 글 진입 시점부터 탈출 시점까지 불변하므로, 1회 생성하면 계속 재사용 하는 것이 좋다.
  • 지금은 AnocatDecorator를 여러 개 생성할 수 없는 상태이다. AnocatDecorator.commit()을 호출하면 AnocatReference가 담고 있던 다른 카테고리 글 목록 자료가 망가지기 때문이다. 붕어빵처럼 객체를 찍어낼 수 없다면 뭐하러 AnocatDecorator를 클래스로 작성했는가? 테스트 용이성이 떨어지고 있다.
  • 그러므로, AnocatPost 싱글톤 객체를 사용하자.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.