diff --git a/rpgsaga/saga/README.md b/rpgsaga/saga/README.md index 3e605f6..35d5170 100644 --- a/rpgsaga/saga/README.md +++ b/rpgsaga/saga/README.md @@ -8,6 +8,26 @@ Diagonal DeclineCall() sendText() readText() + + drive +cdDrive dwdDrive +(write) (write) + combo() + write()??? + +class Combo(cdDrive, dvdDrive) + + Animal + Mamal + canine feline +dog wolf cat, tiger +voice() +display() + + + + + BabushkaPhone SmartPhone LandLinePhone AndroidPhone IOSPhone Symbian diff --git a/rpgsaga/saga/src/EShop.ts b/rpgsaga/saga/src/EShop.ts new file mode 100644 index 0000000..c870a62 --- /dev/null +++ b/rpgsaga/saga/src/EShop.ts @@ -0,0 +1,19 @@ +import { IDisplayable } from './IDisplayable'; +import { Phone } from './phone'; + +export class Eshop { + private stuff: IDisplayable[]; + constructor() { + this.stuff = []; + } + + addStuff(item: IDisplayable) { + this.stuff.push(item); + } + + showStuff() { + for (const itm of this.stuff) { + console.log(itm.display()); + } + } +} diff --git a/rpgsaga/saga/src/IAndroidApp.ts b/rpgsaga/saga/src/IAndroidApp.ts new file mode 100644 index 0000000..b3af0c1 --- /dev/null +++ b/rpgsaga/saga/src/IAndroidApp.ts @@ -0,0 +1,5 @@ +import { IApplication } from './IApplication'; + +export interface IAndroidApp extends IApplication { + checkSecurity(): void; +} diff --git a/rpgsaga/saga/src/IApplication.ts b/rpgsaga/saga/src/IApplication.ts new file mode 100644 index 0000000..9c6c082 --- /dev/null +++ b/rpgsaga/saga/src/IApplication.ts @@ -0,0 +1,6 @@ +export interface IApplication { + readonly name: string; + install(): void; + run(): void; + uninstall(): void; +} \ No newline at end of file diff --git a/rpgsaga/saga/src/IDisplayable.ts b/rpgsaga/saga/src/IDisplayable.ts new file mode 100644 index 0000000..76a21ba --- /dev/null +++ b/rpgsaga/saga/src/IDisplayable.ts @@ -0,0 +1,3 @@ +export interface IDisplayable { + display(): string; +} diff --git a/rpgsaga/saga/src/IIOsApp.ts b/rpgsaga/saga/src/IIOsApp.ts new file mode 100644 index 0000000..a2e42ca --- /dev/null +++ b/rpgsaga/saga/src/IIOsApp.ts @@ -0,0 +1,5 @@ +import { IApplication } from './IApplication'; + +export interface IIosApp extends IApplication { + checkSignature(): void; +} diff --git a/rpgsaga/saga/src/babushkaphone.ts b/rpgsaga/saga/src/babushkaphone.ts new file mode 100644 index 0000000..b03be69 --- /dev/null +++ b/rpgsaga/saga/src/babushkaphone.ts @@ -0,0 +1,3 @@ +import { CellPhone } from './cellphone'; + +export class Babushkaphone extends CellPhone {} diff --git a/rpgsaga/saga/src/cellphone.ts b/rpgsaga/saga/src/cellphone.ts new file mode 100644 index 0000000..24388e3 --- /dev/null +++ b/rpgsaga/saga/src/cellphone.ts @@ -0,0 +1,30 @@ +import { Phone } from './phone'; + +export abstract class CellPhone extends Phone { + diagonal: number; + + display(): string { + return `i'm cellphone ${this.name}`; + } + + constructor(number: string, year: number, diagonal: number, public name?: string) { + console.log('Creating cellphone'); + super(number, year, name); + this.diagonal = diagonal; + } + + call(number: string): void { + console.log(`making call by cellphone ${number}`); + } + + declaineCall() { + console.log('declaing call'); + } + sendMessage(text: string, num: number) { + console.log(`sending ${text} to ${num}`); + } + + readMessage() { + console.log('reading incoming messages'); + } +} diff --git a/rpgsaga/saga/src/index.ts b/rpgsaga/saga/src/index.ts index 7805559..2108b75 100644 --- a/rpgsaga/saga/src/index.ts +++ b/rpgsaga/saga/src/index.ts @@ -1,16 +1,72 @@ import { Phone } from './phone'; +import { CellPhone } from './cellphone'; +import { LandlinePhone } from './landlinephone'; +import { Babushkaphone } from './babushkaphone'; +import { Eshop } from './EShop'; -const first = new Phone('+7900-000 000 (123)', 1990, 'Телефон 1'); +const first = new LandlinePhone('+7900-000 000 (123)', 1990, 'Телефон 1'); first.year = 1998; -first.year = -1998; +try { + first.year = -1998; +} catch (e) { + console.log(e); +} first.call('12345'); first.endCall(); -const second = new Phone('+799900000', -5); -// second.name = 'Телефон 2'; -console.log(second.year); -second.call('12345'); -second.endCall(); +try { + const second = new LandlinePhone('+799900000', -5); + // second.name = 'Телефон 2'; + console.log(second.year); + second.call('12345'); + second.endCall(); +} catch (e) { + console.log(e); +} +const cp1: CellPhone = new Babushkaphone('+79000000000', 2010, 5, 'samsung'); +cp1.call('12345'); +cp1.endCall(); +cp1.sendMessage('some message', 1234); -console.log(first, second, Phone.phoneCount); +const cp2 = new Babushkaphone('+79000000000', 2010, 5, 'samsung'); +cp2.call('1234111111'); +cp2.endCall(); +console.log(`${cp2}`); + +const tmp = ` + /\\ /\\ Todd Vargo + //\\\\_//\\\\ ____ + \\_ _/ / / + / * * \\ /^^^] + \\_\\O/_/ [ ] + / \\_ [ / + \\ \\_ / / + [ [ / \\/ _/ + _[ [ \\ /_/ +`; +console.log(tmp); + +const phones: Array = [cp2, cp1, first]; +for (const phone of phones) { + console.log(phone.display()); +} + +const someReq = () => { + throw new Error('Something bad happend'); +}; + +try { + someReq(); + console.log('success'); +} catch (e) { + console.log(`failed ${e}`); +} +console.log('after finally'); + +const shop = new Eshop(); + +shop.addStuff(cp1); +shop.addStuff(cp2); +shop.addStuff(first); +shop.showStuff(); diff --git a/rpgsaga/saga/src/landlinephone.ts b/rpgsaga/saga/src/landlinephone.ts new file mode 100644 index 0000000..82fc26a --- /dev/null +++ b/rpgsaga/saga/src/landlinephone.ts @@ -0,0 +1,7 @@ +import { Phone } from './phone'; + +export class LandlinePhone extends Phone { + display(): string { + return `i'm landline phone`; + } +} diff --git a/rpgsaga/saga/src/pen.ts b/rpgsaga/saga/src/pen.ts new file mode 100644 index 0000000..95e12c1 --- /dev/null +++ b/rpgsaga/saga/src/pen.ts @@ -0,0 +1,11 @@ +import { IDisplayable } from './IDisplayable'; + +export class Pen implements IDisplayable { + name: string; + constructor(name: string) { + this.name = name; + } + display(): string { + return `stylus ${this.name}`; + } +} diff --git a/rpgsaga/saga/src/phone.ts b/rpgsaga/saga/src/phone.ts index d310d29..0222062 100644 --- a/rpgsaga/saga/src/phone.ts +++ b/rpgsaga/saga/src/phone.ts @@ -1,10 +1,13 @@ -export class Phone { +import { IDisplayable } from './IDisplayable'; + +export abstract class Phone implements IDisplayable { private aYear: number; phoneNumber: string; static phoneCount = 0; constructor(number: string, year: number, public name?: string) { + console.log('Creating phone'); Phone.phoneCount += 1; this.phoneNumber = number; this.year = year; @@ -19,10 +22,20 @@ export class Phone { } set year(year: number) { - this.aYear = year >= 1900 && year < 2023 ? year : this.aYear ?? 1900; + if (year >= 1900 && year < 2023) { + this.aYear = year; + return; + } + throw new Error(`incorrect year`); } get year(): number { return this.aYear; } -} \ No newline at end of file + + toString(): string { + return `this is phone ${this.name}`; + } + + abstract display(): string; +} diff --git a/rpgsaga/saga/src/smartphone.ts b/rpgsaga/saga/src/smartphone.ts new file mode 100644 index 0000000..f09da86 --- /dev/null +++ b/rpgsaga/saga/src/smartphone.ts @@ -0,0 +1,11 @@ +import { IApplication } from './IApplication'; +import { CellPhone } from './cellphone'; + +export abstract class Smartphone extends CellPhone { + apps: IApplication[]; + + constructor(number: string, year: number, diagonal: number, public name?: string) { + super(number, year, diagonal, name); + this.apps = []; + } +}