This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function configureEvent(config) { | |
let createEvent; | |
switch (config.os) { | |
case 'ios': | |
createEvent = createAppleEvent; | |
break; | |
case 'chromeos': | |
createEvent = createGoogleEvent; | |
break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function application(createEvent) { | |
createEvent({name: 'Abstract Factory Pattern', date: new Date(), participants: []}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createOutlookEvent({name, date, participants}) { | |
MicrosoftAPI.createEvent({title: name, date, users: participants}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createAppleEvent({name, date, participants}) { | |
AppleAPI.createEvent({name, date, participants}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createGoogleEvent({name, date, participants}) { | |
GoogleAPI.createEvent({title: name, date, invitees: participants}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface CreateEventArgs { | |
name: string; | |
date: Date; | |
participants: string[]; | |
} | |
export interface Calendar { | |
createEvent: (options: CreateEventArgs) => void; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GoogleCalendar implements Calendar { | |
public createEvent({name, date, participants}: CreateEventArgs): void { | |
GoogleAPI.createEvent({title: name, date, invitees: participants}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppleCalendar implements Calendar { | |
public createEvent({name, date, participants}: CreateEventArgs): void { | |
AppleAPI.createEvent({name, date, participants}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OutlookCalendar implements Calendar { | |
public createEvent({name, date, participants}: CreateEventArgs): void { | |
MicrosoftAPI.createEvent({title: name, date, users: participants}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application { | |
calendar: Calendar; | |
constructor(calendar: Calendar) { | |
this.calendar = calendar; | |
} | |
run(): void { | |
this.calendar.createEvent({name: 'Abstract Factory Pattern', date: new Date(), participants: []}); | |
} |