Bridge

by Artem

JavaScript

'use strict';

class LogTime {
  setImplementor(implementor) {
    this.implementor = implementor;
    return this;
  }
  showTime() {
    console.log(this.implementor.getTime());
  }
}

class AlertTime {
  setImplementor(implementor) {
    this.implementor = implementor;
    return this;
  }
  showTime() {
    console.warn(this.implementor.getTime());
  }
}

class LocaleTime {
  constructor() {
    this.date = new Date();
  }
  getTime() {
    return this.date.toString();
  }
}

class UTCTime {
  constructor() {
    this.date = new Date();
  }
  getTime() {
    return this.date.toUTCString();
  }
}

const localeTime = new LocaleTime();
const utcTime = new UTCTime();

new LogTime().setImplementor(localeTime).showTime();
new AlertTime().setImplementor(localeTime).showTime();

new LogTime().setImplementor(utcTime).showTime();
new AlertTime().setImplementor(utcTime).showTime();