Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lesson_47
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Анамария Морено
lesson_47
Commits
c0cf38b6
Commit
c0cf38b6
authored
7 months ago
by
Анамария Морено
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
39 changed files
with
531 additions
and
0 deletions
+531
-0
ITransport.js
build/factory-pattern/ITransport.js
+2
-0
Ship.js
build/factory-pattern/Ship.js
+9
-0
Truck.js
build/factory-pattern/Truck.js
+9
-0
ShipCreator.js
build/factory-pattern/factory/ShipCreator.js
+11
-0
TransportCreator.js
build/factory-pattern/factory/TransportCreator.js
+10
-0
TruckCreator.js
build/factory-pattern/factory/TruckCreator.js
+11
-0
Ship.js
build/factory-pattern/tranport/Ship.js
+9
-0
Truck.js
build/factory-pattern/tranport/Truck.js
+9
-0
Ship.js
build/factory-pattern/transport/Ship.js
+9
-0
Truck.js
build/factory-pattern/transport/Truck.js
+9
-0
index.js
build/index.js
+41
-0
UserDocument.js
build/state-pattern/UserDocument.js
+27
-0
DraftState.js
build/state-pattern/state/DraftState.js
+18
-0
ModeratedState.js
build/state-pattern/state/ModeratedState.js
+25
-0
PublishedState.js
build/state-pattern/state/PublishedState.js
+16
-0
State.js
build/state-pattern/state/State.js
+9
-0
Context.js
build/strategy-pattern/Context.js
+12
-0
IStrategy.js
build/strategy-pattern/IStrategy.js
+2
-0
AddStrategy.js
build/strategy-pattern/strategy/AddStrategy.js
+9
-0
MultiplyStrategy.js
build/strategy-pattern/strategy/MultiplyStrategy.js
+9
-0
SubstractStrategy.js
build/strategy-pattern/strategy/SubstractStrategy.js
+9
-0
ITransport.ts
src/factory-pattern/ITransport.ts
+4
-0
ShipCreator.ts
src/factory-pattern/factory/ShipCreator.ts
+10
-0
TransportCreator.ts
src/factory-pattern/factory/TransportCreator.ts
+11
-0
TruckCreator.ts
src/factory-pattern/factory/TruckCreator.ts
+10
-0
Ship.ts
src/factory-pattern/transport/Ship.ts
+8
-0
Truck.ts
src/factory-pattern/transport/Truck.ts
+8
-0
index.ts
src/index.ts
+52
-0
UserDocument.ts
src/state-pattern/UserDocument.ts
+53
-0
DraftState.ts
src/state-pattern/state/DraftState.ts
+16
-0
ModeratedState.ts
src/state-pattern/state/ModeratedState.ts
+22
-0
PublishedState.ts
src/state-pattern/state/PublishedState.ts
+14
-0
State.ts
src/state-pattern/state/State.ts
+16
-0
Context.ts
src/strategy-pattern/Context.ts
+14
-0
IStrategy.ts
src/strategy-pattern/IStrategy.ts
+4
-0
AddStrategy.ts
src/strategy-pattern/strategy/AddStrategy.ts
+8
-0
MultiplyStrategy.ts
src/strategy-pattern/strategy/MultiplyStrategy.ts
+8
-0
SubstractStrategy.ts
src/strategy-pattern/strategy/SubstractStrategy.ts
+8
-0
tsconfig.json
tsconfig.json
+0
-0
No files found.
build/factory-pattern/ITransport.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
This diff is collapsed.
Click to expand it.
build/factory-pattern/Ship.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
Ship
=
void
0
;
class
Ship
{
transfer
(
country
,
transferItem
)
{
console
.
log
(
`Груз плывет по морю в
${
country
}
`
);
}
}
exports
.
Ship
=
Ship
;
This diff is collapsed.
Click to expand it.
build/factory-pattern/Truck.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
Truck
=
void
0
;
class
Truck
{
transfer
(
country
,
transferItem
)
{
console
.
log
(
`Груз проехал по суше в страну
${
country
}
`
);
}
}
exports
.
Truck
=
Truck
;
This diff is collapsed.
Click to expand it.
build/factory-pattern/factory/ShipCreator.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
ShipCreator
=
void
0
;
const
Ship_1
=
require
(
"../transport/Ship"
);
const
TransportCreator_1
=
require
(
"./TransportCreator"
);
class
ShipCreator
extends
TransportCreator_1
.
TransportCreator
{
factoryMethod
()
{
return
new
Ship_1
.
Ship
();
}
}
exports
.
ShipCreator
=
ShipCreator
;
This diff is collapsed.
Click to expand it.
build/factory-pattern/factory/TransportCreator.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
TransportCreator
=
void
0
;
class
TransportCreator
{
transfer
(
country
,
transferItem
)
{
const
transport
=
this
.
factoryMethod
();
transport
.
transfer
(
country
,
transferItem
);
}
}
exports
.
TransportCreator
=
TransportCreator
;
This diff is collapsed.
Click to expand it.
build/factory-pattern/factory/TruckCreator.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
TruckCreator
=
void
0
;
const
Truck_1
=
require
(
"../transport/Truck"
);
const
TransportCreator_1
=
require
(
"./TransportCreator"
);
class
TruckCreator
extends
TransportCreator_1
.
TransportCreator
{
factoryMethod
()
{
return
new
Truck_1
.
Truck
();
}
}
exports
.
TruckCreator
=
TruckCreator
;
This diff is collapsed.
Click to expand it.
build/factory-pattern/tranport/Ship.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
Ship
=
void
0
;
class
Ship
{
transfer
(
country
,
transferItem
)
{
console
.
log
(
`Груз плывет по морю в
${
country
}
`
);
}
}
exports
.
Ship
=
Ship
;
This diff is collapsed.
Click to expand it.
build/factory-pattern/tranport/Truck.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
Truck
=
void
0
;
class
Truck
{
transfer
(
country
,
transferItem
)
{
console
.
log
(
`Груз проехал по суше в страну
${
country
}
`
);
}
}
exports
.
Truck
=
Truck
;
This diff is collapsed.
Click to expand it.
build/factory-pattern/transport/Ship.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
Ship
=
void
0
;
class
Ship
{
transfer
(
country
,
transferItem
)
{
console
.
log
(
`Груз плывет по морю в
${
country
}
`
);
}
}
exports
.
Ship
=
Ship
;
This diff is collapsed.
Click to expand it.
build/factory-pattern/transport/Truck.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
Truck
=
void
0
;
class
Truck
{
transfer
(
country
,
transferItem
)
{
console
.
log
(
`Груз проехал по суше в страну
${
country
}
`
);
}
}
exports
.
Truck
=
Truck
;
This diff is collapsed.
Click to expand it.
build/index.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Context_1
=
require
(
"./strategy-pattern/Context"
);
const
AddStrategy_1
=
require
(
"./strategy-pattern/strategy/AddStrategy"
);
const
MultiplyStrategy_1
=
require
(
"./strategy-pattern/strategy/MultiplyStrategy"
);
const
SubstractStrategy_1
=
require
(
"./strategy-pattern/strategy/SubstractStrategy"
);
function
clientCode
(
creator
)
{
let
isTruck
=
true
;
const
country
=
"Kazakhstan"
;
const
goods
=
[
"bmw"
,
"zeekr"
];
creator
.
transfer
(
country
,
goods
);
// if (isTruck) {
// const truck = new Truck();
// truck.transfer(country, goods);
// } else {
// const ship = new Ship();
// ship.transfer(country, goods);
// }
}
// console.log('Запускается реализация для сухопутной перевозки');
// clientCode(new TruckCreator());
// console.log('Запускается реализация для морской перевозки');
// clientCode(new ShipCreator());
// const doc: UserDocument = new UserDocument("admin");
// doc.sendForModeration();
// doc.sendForModeration();
// doc.sendForPublication();
// doc.sendForDraft();
let
action
=
"multiply"
;
let
context
=
new
Context_1
.
Context
();
if
(
action
===
"add"
)
{
context
.
setStrategy
(
new
AddStrategy_1
.
AddStrategy
());
}
else
if
(
action
===
"subsctract"
)
{
context
.
setStrategy
(
new
SubstractStrategy_1
.
SubstractStrategy
());
}
else
{
context
.
setStrategy
(
new
MultiplyStrategy_1
.
MultiplyStrategy
());
}
const
result
=
context
.
execute
(
5
,
3
);
console
.
log
(
result
);
This diff is collapsed.
Click to expand it.
build/state-pattern/UserDocument.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
UserDocument
=
void
0
;
const
DraftState_1
=
require
(
"./state/DraftState"
);
class
UserDocument
{
constructor
(
user
)
{
this
.
_currentUser
=
user
;
this
.
changeState
(
new
DraftState_1
.
DraftState
());
}
changeState
(
state
)
{
this
.
_state
=
state
;
this
.
_state
.
setDocument
(
this
);
}
get
currentUser
()
{
return
this
.
_currentUser
;
}
sendForDraft
()
{
this
.
_state
.
draft
();
}
sendForModeration
()
{
this
.
_state
.
moderate
();
}
sendForPublication
()
{
this
.
_state
.
publish
();
}
}
exports
.
UserDocument
=
UserDocument
;
This diff is collapsed.
Click to expand it.
build/state-pattern/state/DraftState.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
DraftState
=
void
0
;
const
ModeratedState_1
=
require
(
"./ModeratedState"
);
const
State_1
=
require
(
"./State"
);
class
DraftState
extends
State_1
.
State
{
draft
()
{
console
.
log
(
"Документ находится в подготовке"
);
}
moderate
()
{
console
.
log
(
"Документ отправлен на модерацию"
);
this
.
document
.
changeState
(
new
ModeratedState_1
.
ModeratedState
());
}
publish
()
{
console
.
log
(
"Документ не прошел модерацию и не может быть опубликован"
);
}
}
exports
.
DraftState
=
DraftState
;
This diff is collapsed.
Click to expand it.
build/state-pattern/state/ModeratedState.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
ModeratedState
=
void
0
;
const
DraftState_1
=
require
(
"./DraftState"
);
const
PublishedState_1
=
require
(
"./PublishedState"
);
const
State_1
=
require
(
"./State"
);
class
ModeratedState
extends
State_1
.
State
{
draft
()
{
console
.
log
(
'Документ отправлен на повторную подготовку'
);
this
.
document
.
changeState
(
new
DraftState_1
.
DraftState
());
}
moderate
()
{
console
.
log
(
'Документ уже находится в модерации'
);
}
publish
()
{
if
(
this
.
document
.
currentUser
===
"admin"
)
{
console
.
log
(
'Отправляем документ на публикацию'
);
this
.
document
.
changeState
(
new
PublishedState_1
.
PublishedState
());
}
else
{
console
.
log
(
'У вас нет прав на публикацию'
);
}
}
}
exports
.
ModeratedState
=
ModeratedState
;
This diff is collapsed.
Click to expand it.
build/state-pattern/state/PublishedState.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
PublishedState
=
void
0
;
const
State_1
=
require
(
"./State"
);
class
PublishedState
extends
State_1
.
State
{
draft
()
{
console
.
log
(
"Документ уже опубликован, нет возможности отправить на подготовку"
);
}
moderate
()
{
console
.
log
(
"Документ уже опубликован, нет возможности отправить на модерацию"
);
}
publish
()
{
console
.
log
(
"Документ уже опубликован"
);
}
}
exports
.
PublishedState
=
PublishedState
;
This diff is collapsed.
Click to expand it.
build/state-pattern/state/State.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
State
=
void
0
;
class
State
{
setDocument
(
document
)
{
this
.
document
=
document
;
}
}
exports
.
State
=
State
;
This diff is collapsed.
Click to expand it.
build/strategy-pattern/Context.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
Context
=
void
0
;
class
Context
{
setStrategy
(
strategy
)
{
this
.
_strategy
=
strategy
;
}
execute
(
a
,
b
)
{
return
this
.
_strategy
.
execute
(
a
,
b
);
}
}
exports
.
Context
=
Context
;
This diff is collapsed.
Click to expand it.
build/strategy-pattern/IStrategy.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
This diff is collapsed.
Click to expand it.
build/strategy-pattern/strategy/AddStrategy.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
AddStrategy
=
void
0
;
class
AddStrategy
{
execute
(
a
,
b
)
{
return
a
+
b
;
}
}
exports
.
AddStrategy
=
AddStrategy
;
This diff is collapsed.
Click to expand it.
build/strategy-pattern/strategy/MultiplyStrategy.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
MultiplyStrategy
=
void
0
;
class
MultiplyStrategy
{
execute
(
a
,
b
)
{
return
a
*
b
;
}
}
exports
.
MultiplyStrategy
=
MultiplyStrategy
;
This diff is collapsed.
Click to expand it.
build/strategy-pattern/strategy/SubstractStrategy.js
0 → 100644
View file @
c0cf38b6
"use strict"
;
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
exports
.
SubstractStrategy
=
void
0
;
class
SubstractStrategy
{
execute
(
a
,
b
)
{
return
a
-
b
;
}
}
exports
.
SubstractStrategy
=
SubstractStrategy
;
This diff is collapsed.
Click to expand it.
src/factory-pattern/ITransport.ts
0 → 100644
View file @
c0cf38b6
export
interface
ITransport
{
transfer
(
country
:
string
,
transferItem
:
string
[]):
void
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/factory-pattern/factory/ShipCreator.ts
0 → 100644
View file @
c0cf38b6
import
{
ITransport
}
from
"../ITransport"
;
import
{
Ship
}
from
"../transport/Ship"
;
import
{
TransportCreator
}
from
"./TransportCreator"
;
export
class
ShipCreator
extends
TransportCreator
{
public
factoryMethod
():
ITransport
{
return
new
Ship
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/factory-pattern/factory/TransportCreator.ts
0 → 100644
View file @
c0cf38b6
import
{
ITransport
}
from
"../ITransport"
;
export
abstract
class
TransportCreator
{
public
abstract
factoryMethod
():
ITransport
;
public
transfer
(
country
:
string
,
transferItem
:
string
[])
{
const
transport
=
this
.
factoryMethod
();
transport
.
transfer
(
country
,
transferItem
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/factory-pattern/factory/TruckCreator.ts
0 → 100644
View file @
c0cf38b6
import
{
ITransport
}
from
"../ITransport"
;
import
{
Truck
}
from
"../transport/Truck"
;
import
{
TransportCreator
}
from
"./TransportCreator"
;
export
class
TruckCreator
extends
TransportCreator
{
public
factoryMethod
():
ITransport
{
return
new
Truck
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/factory-pattern/transport/Ship.ts
0 → 100644
View file @
c0cf38b6
import
{
ITransport
}
from
"../ITransport"
;
export
class
Ship
implements
ITransport
{
transfer
(
country
:
string
,
transferItem
:
string
[]):
void
{
console
.
log
(
`Груз плывет по морю в
${
country
}
`
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/factory-pattern/transport/Truck.ts
0 → 100644
View file @
c0cf38b6
import
{
ITransport
}
from
"../ITransport"
;
export
class
Truck
implements
ITransport
{
transfer
(
country
:
string
,
transferItem
:
string
[]):
void
{
console
.
log
(
`Груз проехал по суше в страну
${
country
}
`
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/index.ts
0 → 100644
View file @
c0cf38b6
import
{
ShipCreator
}
from
"./factory-pattern/factory/ShipCreator"
;
import
{
TransportCreator
}
from
"./factory-pattern/factory/TransportCreator"
;
import
{
TruckCreator
}
from
"./factory-pattern/factory/TruckCreator"
;
import
{
UserDocument
}
from
"./state-pattern/UserDocument"
;
import
{
Context
}
from
"./strategy-pattern/Context"
;
import
{
AddStrategy
}
from
"./strategy-pattern/strategy/AddStrategy"
;
import
{
MultiplyStrategy
}
from
"./strategy-pattern/strategy/MultiplyStrategy"
;
import
{
SubstractStrategy
}
from
"./strategy-pattern/strategy/SubstractStrategy"
;
function
clientCode
(
creator
:
TransportCreator
)
{
let
isTruck
=
true
;
const
country
=
"Kazakhstan"
;
const
goods
=
[
"bmw"
,
"zeekr"
];
creator
.
transfer
(
country
,
goods
);
// if (isTruck) {
// const truck = new Truck();
// truck.transfer(country, goods);
// } else {
// const ship = new Ship();
// ship.transfer(country, goods);
// }
}
// console.log('Запускается реализация для сухопутной перевозки');
// clientCode(new TruckCreator());
// console.log('Запускается реализация для морской перевозки');
// clientCode(new ShipCreator());
// const doc: UserDocument = new UserDocument("admin");
// doc.sendForModeration();
// doc.sendForModeration();
// doc.sendForPublication();
// doc.sendForDraft();
let
action
=
"add"
;
let
context
=
new
Context
();
if
(
action
===
"add"
)
{
context
.
setStrategy
(
new
AddStrategy
());
}
else
if
(
action
===
"subsctract"
)
{
context
.
setStrategy
(
new
SubstractStrategy
());
}
else
{
context
.
setStrategy
(
new
MultiplyStrategy
());
}
const
result
=
context
.
execute
(
5
,
3
);
console
.
log
(
result
);
This diff is collapsed.
Click to expand it.
src/state-pattern/UserDocument.ts
0 → 100644
View file @
c0cf38b6
import
{
DraftState
}
from
"./state/DraftState"
;
import
{
State
}
from
"./state/State"
;
export
class
UserDocument
{
private
_state
!
:
State
;
private
_currentUser
:
string
;
constructor
(
user
:
string
)
{
this
.
_currentUser
=
user
;
this
.
changeState
(
new
DraftState
());
}
public
changeState
(
state
:
State
)
{
this
.
_state
=
state
;
this
.
_state
.
setDocument
(
this
);
}
get
currentUser
():
string
{
return
this
.
_currentUser
;
}
public
sendForDraft
():
void
{
this
.
_state
.
draft
();
}
public
sendForModeration
():
void
{
this
.
_state
.
moderate
();
}
public
sendForPublication
():
void
{
this
.
_state
.
publish
();
}
// public publish() {
// switch(this._state) {
// case 'draft':
// this._state = 'moderation';
// break;
// case 'moderation':
// if (this._currentUser === 'admin') {
// this._state = 'published';
// } else {
// console.log('У вас нет прав');
// }
// break;
// case 'published':
// break;
// }
// }
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/state-pattern/state/DraftState.ts
0 → 100644
View file @
c0cf38b6
import
{
ModeratedState
}
from
"./ModeratedState"
;
import
{
State
}
from
"./State"
;
export
class
DraftState
extends
State
{
public
override
draft
():
void
{
console
.
log
(
"Документ находится в подготовке"
);
}
public
override
moderate
():
void
{
console
.
log
(
"Документ отправлен на модерацию"
);
this
.
document
.
changeState
(
new
ModeratedState
());
}
public
override
publish
():
void
{
console
.
log
(
"Документ не прошел модерацию и не может быть опубликован"
);
}
}
This diff is collapsed.
Click to expand it.
src/state-pattern/state/ModeratedState.ts
0 → 100644
View file @
c0cf38b6
import
{
DraftState
}
from
"./DraftState"
;
import
{
PublishedState
}
from
"./PublishedState"
;
import
{
State
}
from
"./State"
;
export
class
ModeratedState
extends
State
{
public
override
draft
():
void
{
console
.
log
(
'Документ отправлен на повторную подготовку'
);
this
.
document
.
changeState
(
new
DraftState
());
}
public
override
moderate
():
void
{
console
.
log
(
'Документ уже находится в модерации'
);
}
public
override
publish
():
void
{
if
(
this
.
document
.
currentUser
===
"admin"
)
{
console
.
log
(
'Отправляем документ на публикацию'
);
this
.
document
.
changeState
(
new
PublishedState
());
}
else
{
console
.
log
(
'У вас нет прав на публикацию'
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/state-pattern/state/PublishedState.ts
0 → 100644
View file @
c0cf38b6
import
{
State
}
from
"./State"
;
export
class
PublishedState
extends
State
{
public
override
draft
():
void
{
console
.
log
(
"Документ уже опубликован, нет возможности отправить на подготовку"
);
}
public
override
moderate
():
void
{
console
.
log
(
"Документ уже опубликован, нет возможности отправить на модерацию"
);
}
public
override
publish
():
void
{
console
.
log
(
"Документ уже опубликован"
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/state-pattern/state/State.ts
0 → 100644
View file @
c0cf38b6
import
{
UserDocument
}
from
"../UserDocument"
;
export
abstract
class
State
{
protected
document
!
:
UserDocument
;
public
setDocument
(
document
:
UserDocument
):
void
{
this
.
document
=
document
;
}
public
abstract
draft
():
void
;
public
abstract
moderate
():
void
;
public
abstract
publish
():
void
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/strategy-pattern/Context.ts
0 → 100644
View file @
c0cf38b6
import
{
IStrategy
}
from
"./IStrategy"
;
export
class
Context
{
private
_strategy
!
:
IStrategy
;
public
setStrategy
(
strategy
:
IStrategy
)
{
this
.
_strategy
=
strategy
;
}
execute
(
a
:
number
,
b
:
number
):
number
{
return
this
.
_strategy
.
execute
(
a
,
b
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/strategy-pattern/IStrategy.ts
0 → 100644
View file @
c0cf38b6
export
interface
IStrategy
{
execute
(
a
:
number
,
b
:
number
):
number
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/strategy-pattern/strategy/AddStrategy.ts
0 → 100644
View file @
c0cf38b6
import
{
IStrategy
}
from
"../IStrategy"
;
export
class
AddStrategy
implements
IStrategy
{
execute
(
a
:
number
,
b
:
number
):
number
{
return
a
+
b
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/strategy-pattern/strategy/MultiplyStrategy.ts
0 → 100644
View file @
c0cf38b6
import
{
IStrategy
}
from
"../IStrategy"
;
export
class
MultiplyStrategy
implements
IStrategy
{
execute
(
a
:
number
,
b
:
number
):
number
{
return
a
*
b
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/strategy-pattern/strategy/SubstractStrategy.ts
0 → 100644
View file @
c0cf38b6
import
{
IStrategy
}
from
"../IStrategy"
;
export
class
SubstractStrategy
implements
IStrategy
{
execute
(
a
:
number
,
b
:
number
):
number
{
return
a
-
b
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tsconfig.json
0 → 100644
View file @
c0cf38b6
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment