应该使用哪种类型的设计模式来创建模拟器?
我已经编写了一个模拟器,但我对如何正确组织它有一些疑问,因为我发现它在类连接(CPU <-> 机器板)方面存在一些问题。 例如:I/O端口、中断、两个或多个CPU之间的通信等。
我需要模拟器具有最佳的性能和对代码的良好理解。
PD:抱歉我的英语不好。
编辑:
要求多种模式。
I have programmed an emulator, but I have some doubts about how to organizate it properly, because, I see that it has some problems about classes connection (CPU <-> Machine Board).
For example: I/O ports, interruptions, communication between two or more CPU, etc.
I need for the emulator to has the best performance and good understanding of the code.
PD: Sorry for my bad English.
EDITED:
Asking for multiple patterns.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里发生了两件密切相关的事情。
模拟器是命令定义的集合。模拟器可以做的每件事都是一个命令。有些命令是嵌套的命令序列。
模拟器有许多内部状态定义。模拟器所做的每一件事都会更新一个或多个状态对象。
You have two closely-related things going on here.
The emulator is a collection of Command definitions. Each thing the emulator can do is a command. Some commands are nested sequences of commands.
The emulator has a number of internal State definitions. Each thing the emulator does updates one or more state objects.
构建您的软件时无需考虑“模式”。如果这些模式是有意为之的话,它们就会自然地从你的工作中消失。构建你的软件以适应他们倾向于什么模式的先入为主的观念,这会使其变得更加庞大并且更难以改变。
(如果您还没有,请下载适合您的语言的单元测试框架并用它来指导您的开发!)
Build your software without regard to "patterns." The patterns will fall naturally out of your work if they are intended to be there. Building your software to fit preconceived notions of what patterns they will tend to make it bulkier and more resistant to change.
(If you haven't yet, download a unit testing framework for your language and use it to guide your development!)
首先看一下 wiki。它似乎为模拟艺术提供了一些切入点。其次,我会看看 QEMU 或 DOSBox 是结构化的。还可以看看 SourceForge。 简单查询< /a> 提供以下软件模拟器:
一般来说,对于如此复杂的任务没有单一的模式。您肯定需要状态机模式,并且您可能会使用命令模式来调度操作。但我真的建议你看看别人的作品。
First have a look at wiki. It seems to give some entry point to art of emulation. Second I would look how QEMU or DOSBox are structured. Also have a look at SourceForge. Simple query gives following software emulators:
In general there is no single pattern for such complicated task. You will definitely need State Machine pattern and you might use Command pattern for dispatching actions. But I really suggest that you will look on other peoples work.