21
loading...
This website collects cookies to deliver better user experience
function Developer(name, registration) {
this.name = name;
this.registration = registration;
}
exports.createJunior = function (name, registration) {
return Object.create(new Developer(name, registration), { position: { value: 'Junior' } })
}
exports.createPleno = function (name, registration) {
return Object.create(new Developer(name, registration), { position: { value: 'Pleno' } })
}
exports.createSenior = function (name, registration) {
return Object.create(new Developer(name, registration), { position: { value: 'Senior' } })
}
const {createJunior, createPleno, createSenior} = require('./prototype');
const junior = createJunior("junior", "123");
const pleno = createPleno("pleno", "456");
const senior = createSenior("senior", "789");
exports.commit = function (Developer) {
let c = Developer.commit();
return c + `Developer ${Developer.position} can committing\n`
}
exports.codeReview = function (Developer) {
let cr = Developer.codeReview();
let test = Developer.position === 'Junior' ? `Developer ${Developer.position} can not make code review` : `Developer ${Developer.position} can make code review`;
return cr + test + '\n';
}
exports.deploy = function (Developer) {
let d = Developer.deploy();
let test = Developer.position !== 'Senior' ? `${Developer.position} can not deploy` : `Only Developers ${Developer.position} can deploy`;
return d + test + '\n';
}
function Developer(name, registration) {
this.name = name;
this.registration = registration;
this.commit = function () {
return "Can I to commit?\n";
};
this.codeReview = function () {
return "Can I to do code review?\n";
};
this.deploy = function () {
return "Can I to do a deploy?\n";
};
}
const {createJunior, createPleno, createSenior} = require('./prototype');
const {commit, codeReview, deploy} = require('./decorator');
const junior = createJunior("junior", "123");
console.log(commit(junior));
console.log(codeReview(junior));
console.log(deploy(junior));
const pleno = createPleno("pleno", "456");
console.log(commit(pleno));
console.log(codeReview(pleno));
console.log(deploy(pleno));
const senior = createSenior("senior", "789");
console.log(commit(senior));
console.log(codeReview(senior));
console.log(deploy(senior));
Can I to commit?
Developer Junior can committing
Can I to do code review?
Developer Junior can not make code review
Can I to do a deploy?
Junior can not deploy
Can I to commit?
Developer Pleno can committing
Can I to do code review?
Developer Pleno can make code review
Can I to do a deploy?
Pleno can not deploy
Can I to commit?
Developer Senior can committing
Can I to do code review?
Developer Senior can make code review
Can I to do a deploy?
Only Developers Senior can deploy
function Memento(state) {
this.state = state;
this.getState = function() {
return this.state;
}
}
function Originator() {
this.state = null;
this.add = function(state) {
this.state = state;
}
this.save = function() {
return new Memento(this.state);
}
this.restore = function(memento) {
return memento.getState();
}
}
function Historic() {
this.states = [];
this.originator = new Originator();
this.add = function(state) {
this.originator.add(state);
this.states.push(this.originator.save());
}
this.getByIndexOrLast = function(i) {
if (!this.states.length) {
return;
}
if (!i && i !== 0) {
i = this.states.length - 1;
}
return this.originator.restore(this.states[i]);
}
this.countSteps = function() {
return this.states.length;
}
this.getStates = function() {
return this.states;
}
}
module.exports = {
Historic: Historic
};
const Historic = require('./memento').Historic;
let juniorHistoric = new Historic();
juniorHistoric.add("Created Junior\n");
juniorHistoric.add("Junior trying to commit\n");
juniorHistoric.add("Junior trying to do code review\n");
juniorHistoric.add("Junior trying to deploy\n");
juniorHistoric.getStates().forEach((memento) => {
console.log(memento.state);
});
let plenoHistoric = new Historic();
plenoHistoric.add("Created Pleno\n");
plenoHistoric.add("Pleno trying to commit\n");
plenoHistoric.add("Pleno trying to do code review\n");
plenoHistoric.add("Pleno trying to deploy\n");
plenoHistoric.getStates().forEach((memento) => {
console.log(memento.state);
});
let seniorHistoric = new Historic();
seniorHistoric.add("Created Senior\n");
seniorHistoric.add("Senior trying to commit\n");
seniorHistoric.add("Senior trying to do code review\n");
seniorHistoric.add("Senior trying to deploy\n");
seniorHistoric.getStates().forEach((memento) => {
console.log(memento.state);
});
Created Junior
Junior trying to commit
Junior trying to do code review
Junior trying to deploy
Created Pleno
Pleno trying to commit
Pleno trying to do code review
Pleno trying to deploy
Created Senior
Senior trying to commit
Senior trying to do code review
Senior trying to deploy