Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Product } from './product.js';
- import { Scent } from './scent.js';
- export class Cream extends Product {
- #scent;
- static #minNameLength = 3;
- static #maxNameLength = 15;
- static #minBrandLength = 3;
- static #maxBrandLength = 15;
- /**
- * @param {string} name
- * @param {string} brand
- * @param {number} price
- * @param {Gender} gender
- * @param {number} milliliters
- * @param {Usage} usage
- */
- constructor(name, brand, price, gender, scent) {
- super(name, brand, price, gender);
- this.validateScent(scent);
- this.#scent = scent;
- }
- validateName(value) {
- if (!value) {
- throw new Error('Invalid name!');
- }
- if (value.length < Cream.#minNameLength || value.length > Cream.#maxNameLength) {
- throw new Error(`Product name length must be between ${Cream.#minNameLength} and ${Cream.#maxNameLength}`);
- }
- }
- validateBrand(value) {
- if (!value) {
- throw new Error('Invalid brand!');
- }
- if (value.length < Cream.#minBrandLength || value.length > Cream.#maxBrandLength) {
- throw new Error(`Product brand length must be between ${Cream.minBrandLength} and ${Cream.maxBrandLength}`);
- }
- }
- get scent() {
- return this.#scent;
- }
- validateScent(value) {
- if (!Scent.hasOwnProperty(value)) {
- // if (!Object.keys(Scent).some(key => Scent[key] === value))
- throw new Error('You should use rose, lavender or vanilla.');
- }
- }
- additionalInfo() {
- return ` #Scent: ${Scent[this.#scent]}`;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment