实施模式设计

时间:2019-05-30 19:23:41

标签: java design-patterns architecture

我有这样的代码,在其中我认为有两种类型的参与者,代码变得很长,我认为我可以应用FACTORY模式,但是如果我要创建一个特定类“ ParticipantOWner”和“普通参与者”?

在此处输入图片说明 enter image description here

我想基于FACTORY PATTERNS的图像创建这些类,在该类中有特定的类LusuryCar,SmallCar和SedanCar

 public Meet createRelacion(Long idOwner, Long idUser) {
            Meet currentMeet = new Meet();
            Bet bet = new Bet();
            bet.setInversion(100);
            currentMeet.setBet(bet);
            currentMeet.setState(State.start);
            currentMeet.setName(Math.random() + "");

            User user = userRepository.findById(idUser);
            User owner = userRepository.findById(idOwner);

            Bet betParticipant = new Bet();
            betParticipant.setInversion(0);
    ///////////////////   FIRST PARTICIPANT  /////////////////
            Participant participant = new Participant();    //
            participant.setRol(Rol.NORMAL);            //
            participant.setMeet(currentMeet);               //
            participant.setUser(user);                      //
            participant.setBet(betParticipant);             //
  ////////////////////////////////////////////////////////////  
            participantRepository.save(participant);
    ///////////////////   SECOND PARTICIPANT  //////////////////
            Participant participantOwner = new Participant();///
            participantOwner.setMeet(currentMeet);           /// 
            participantOwner.setRol(Rol.OWNER);              ///
            participantOwner.setUser(owner);                 ///
   /////////////////////////////////////////////////////////////
            participantRepository.save(participantOwner);
            return currentMeet;
        }

0 个答案:

没有答案