Hello I am in doubt to apply the separation of concerns concept in two classes(您好,我不确定将关注点分离概念应用于两个类别)
I basically have my class(我基本上上课了)
to create a match(建立比赛)
class Match {
constructor (players) {
this.id = uuid.v4 (). toString ();
this.players = players;
this.isActive = false;
}
// Match rest methods ...
}
module.exports = Match;
and how I need a match collection to do a socket.io logic(以及我如何需要匹配集合来执行socket.io逻辑)
or need an array of these matchs to access when needed(或需要这些匹配项的数组以在需要时进行访问)
and i make this class Matches or MatchManager:(我使此类Matches或MatchManager:)
class Matches {
constructor() {
this.matches = [];
}
addMatch(match) {
if(match){
this.matches.push(match);
}
}
getMatch(id){
if(id){
return this.matches.find((match) => match.id = match )
}else{
return null;
}
}
}
module.exports = Matches;
In my class match I have my isActive that I will start and finish a game using isActive setting to true or false(在课堂比赛中,我拥有isActive,我将使用isActive设置为true或false来开始和结束游戏)
so a function startMatch () and endMatch ()(所以一个函数startMatch()和endMatch())
that I would need to change my isActive to true or false, but I am unsure how to do this in a function (accessing a specific match)(我需要将isActive更改为true或false,但是我不确定如何在函数中执行此操作(访问特定匹配项))
and also with this design I have another problem(而且在这种设计下,我还有另一个问题)
and another doubt Could I create a match function to create a Match?(还有另一个疑问,我可以创建一个匹配函数来创建一个匹配吗?)
ask by gabriel translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…