简体   繁体   English

如何根据需求或功能设计类

[英]How to design classes based on requirements or functionality

I'm struggling with class design. 我在课堂设计上苦苦挣扎。 Sometimes I think that all I have read about class organization, class diagram and class design can not apply to the concrete project. 有时我认为我所读到的关于班级组织,班级图和班级设计的所有内容都不适用于具体项目。 I want to create Snake game in Java using MVC or MVP architecture. 我想使用MVC或MVP架构在Java中创建Snake游戏。

There are some requirements: 有一些要求:

  • The snake and food for snake should be drawn on screen 蛇的蛇和食物应该画在屏幕上
  • It should be displayed current game score 它应该显示当前的游戏分数
  • The snake should move using key arrow 蛇应该用关键箭头移动
  • The food should be grouped so each group have some amount of point and color 食物应分组,以便每组都有一定的点和颜色
  • Game speed should be determined on score threshold 应根据得分阈值确定游戏速度

The question is how to organize classes (with methods and "all") according that requirements? 问题是如何根据要求组织类(使用方法和“所有”)? Maybe someone have a book or link to suggest with guidance or examples. 也许某人有书或链接建议指导或示例。

Please could you share your rule of thumb for creating and organizing classes through this example? 请您通过此示例分享您创建和组织课程的经验法则吗?

Here is an example of a simple Snake game clone in Java that you might refer to for ideas on how to structure things. 下面是 Java中一个简单的Snake游戏克隆示例 ,您可以参考该示例来了解如何构建事物。

Since you ask for a book recommendation, I would recommend a book that helped me immensely in grasping object oriented analysis and design. 既然你要求推荐书籍,我会推荐一本能帮助我掌握面向对象分析和设计的书。 It teaches you by solving real problems step by step. 它通过逐步解决实际问题来教你。 It is quite different as it does not follow the typical flow of technical books on the matter. 它完全不同,因为它没有遵循关于此事的典型技术书籍流程。 It looks at gradually harder problems pointing at potential problems and explaining the important concepts along the way. 它着眼于指出潜在问题的逐渐困难的问题,并解释了这一过程中的重要概念。

The book is called Head First OOA&D . 这本书被称为Head First OOA&D I recommend it because it is an easy (and sometimes even funny) read, with lots of samples in Java and on top of that, there is a game example in it. 我推荐它,因为它是一个简单的(有时甚至是有趣的)读取,在Java中有很多样本,除此之外,还有一个游戏示例。 So be sure to check it out! 所以一定要看看! Even outside the context of your problem I think you can benefit from it the way I did. 即使在问题的背景之外,我认为你可以像我一样从中受益。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM