Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createComputerHierarchy() {
- class BaseClass {
- constructor(manufacturer) {
- if (new.target === BaseClass) {
- throw new Error("cant do that");
- }
- this.manufacturer = manufacturer;
- }
- }
- class Keyboard extends BaseClass {
- constructor(manufacturer, responseTime) {
- super(manufacturer);
- this.responseTime = responseTime;
- }
- }
- class Monitor extends BaseClass {
- constructor(manufacturer, width, height) {
- super(manufacturer);
- this.width = width;
- this.height = height;
- }
- }
- class Battery extends BaseClass {
- constructor(manufacturer, expectedLife) {
- super(manufacturer);
- this.expectedLife = expectedLife;
- }
- }
- class Computer extends BaseClass {
- constructor(manufacturer, processorSpeed, ram, hardDiskSpace) {
- super(manufacturer);
- if (new.target === BaseClass) {
- throw new Error("cant do that");
- }
- this.processorSpeed = processorSpeed;
- this.ram = ram;
- this.hardDiskSpace = hardDiskSpace;
- }
- }
- class Laptop extends Computer {
- constructor(manufacturer, processorSpeed, ram, hardDiskSpace, weight,color,battery) {
- super(manufacturer, processorSpeed, ram, hardDiskSpace);
- this.weight = weight;
- this.color = color;
- this._battery = battery;
- }
- set battery(bat) {
- if(!bat instanceof Battery) {
- throw new TypeError("error")
- }
- this._battery = bat;
- }
- get battery() {
- return this._battery;
- }
- }
- class Desktop extends Computer {
- constructor(manufacturer, processorSpeed, ram, hardDiskSpace,keyboard,monitor) {
- super(manufacturer, processorSpeed, ram, hardDiskSpace);
- this._keyboard = keyboard;
- this._monitor = monitor;
- }
- set keyboard(keyboard) {
- if(!keyboard instanceof Keyboard) {
- throw new TypeError("error")
- }
- this._keyboard = keyboard;
- }
- get keyboard() {
- return this._keyboard;
- }
- set monitor(monitor) {
- if(!monitor instanceof Monitor) {
- throw new TypeError("error")
- }
- return this._monitor = monitor;
- }
- get monitor() {
- return this._monitor;
- }
- }
- return {
- Battery,
- Keyboard,
- Monitor,
- Computer,
- Laptop,
- Desktop
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement