Java OOD and code duplication

前端 未结 2 1152
走了就别回头了
走了就别回头了 2021-01-29 10:48

I started creating a basic roleplaying game, and now I work on the basics. I have a code duplication for creating new characters and for existed character, which is a very bad t

2条回答
  •  甜味超标
    2021-01-29 11:07

    suggestions:

    1. CharacterCreator.CharacterCreator(). Method should be verb and describe action, i.e createCharacter
    2. look ad design pattern Factory. Your Creator is 'Factory'. The method 'createCharacter' should take parameter characterType. That means, that getting info from System.in should be done in class who invoke that method.
    3. Add enum for characterClass with mapping to numbers (look to inner map in enum).

提交回复
热议问题