xoxama

Cosmetics >> generic-product

Jun 10th, 2020
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. >> generic-product <<
  2.  
  3. import { Validator } from '../common/validators';
  4. import { GenderType } from "../common/gender-type";
  5.  
  6. export abstract class Product {
  7. protected _price: number;
  8. protected _name: string;
  9. protected _brand: string;
  10. protected _gender: GenderType;
  11.  
  12. public constructor(name: string, brand: string, price: number, gender: GenderType) {
  13. Validator.validateObject(name);
  14. Validator.validatePrice(price);
  15.  
  16. this._name = name;
  17. this._brand = brand;
  18. this._price = price;
  19. this._gender = gender;
  20. }
  21.  
  22. public get name(): string {
  23. return this.name;
  24. }
  25.  
  26. public get price(): number {
  27. return this.price;
  28. }
  29.  
  30. public get brand(): string {
  31. return this.brand;
  32. }
  33.  
  34. public get gender(): GenderType {
  35. return this.gender;
  36. }
  37.  
  38. public print(): string {
  39. return `#${this.name} ${this.brand}\r\n #Price: \$${this.price}\r\n #Gender: ${GenderType[this.gender]}\r\n`;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment