Giter Club home page Giter Club logo

the-oop-till's Introduction

The Task

Write object-oriented code to model a till.

The objects under test:

  • The Product represents a product with an id, label, and price
  • The Catalog lists all available products available at the shop
  • The Till lists purchased products and generates bill

How To Run

Simply run yarn install at the top-level to install the required modules.

Then run jest to run all tests.

All tests in the-oop-till.test.js should be made to pass. You can start with the first test at the top and make your way down. Do not modify the tests. You should be able to make them pass simply by fleshing out the code under test.

Prototypal Inheritance

The code starts out using prototypal inheritance: you can just flesh out the function definitions and make judicious use of the this keyword.

ES6 Classes

Once your tests are passing, convert your objects to ES6 class syntax. For example, a skeleton of the Product class would look like this:

class Product {
  constructor(id, label, preTaxPrice){
  }

  getId(){
  }

  getPreTaxPrice(){
  }

  getLineItemDescription(){
  }
}

Alternatives to Object-oriented Programming

Some consider constructor functions and classes an anti-pattern in JavaScript.

  • How would you model the till without resorting to classes?
  • How could Object.create help you?
  • The Till object needs the catalog to generate the bill. An alternative design would be to mix in the catalog functionality into the Till object. How would you do that?

the-oop-till's People

Contributors

matstc avatar

Watchers

Martin Carel avatar James Cloos avatar

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.