-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
200 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IApplication } from './IApplication'; | ||
|
||
export interface IAndroidApp extends IApplication { | ||
checkSecurity(): void; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface IApplication { | ||
readonly name: string; | ||
install(): void; | ||
run(): void; | ||
uninstall(): void; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IDisplayable { | ||
display(): string; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { IApplication } from './IApplication'; | ||
|
||
export interface IIosApp extends IApplication { | ||
checkSignature(): void; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { CellPhone } from './cellphone'; | ||
|
||
export class Babushkaphone extends CellPhone {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Phone> = [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(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Phone } from './phone'; | ||
|
||
export class LandlinePhone extends Phone { | ||
display(): string { | ||
return `i'm landline phone`; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`; | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = []; | ||
} | ||
} |