English 中文(简体)
OOP设计——制定战略/赞助
原标题:OOP design - creation strategies/patterns

For OOP practice I am working on a hobby project, a quiz program which reads a table from txt file and asks questions about entries in the table. The idea is to have this facilitate learning of the material given for a course in our dept.

至今,我撰写了I/Obit,把极小的“全球倡议”和类别汇集在一起,在数据表中代表不同类型的实体。 我不知道如何处理该方案的核心,尽管我指的是提问和鉴定。

我的第一个想法是有一个类别<代码>。 摘要问题,其中粗略地界定了问题是什么以及它拥有哪些领域(代表、答案和困难程度)。 然后,我认为我可以就不同类型的问题撰写课程,例如,一个简单的价值调查类别(如给实体的名称和要求某个特定财产),另一个类别则涉及更复杂的问题(例如询问实体的互动等)。

不过,我不清楚这是否是最好的前进道路。 确切地说,为什么,但我感觉到,这不是解决问题的绝迹。 工厂类别的工作是否有意义? 基本上,我需要:

  • provide means for a question to be generated based on one, or more, entities randomly picked from the datatable
  • different types of questions need to be created on the runtime, based on input from the user (desired difficulty level)
  • questions need to be validated and the user needs to be notified by the main Quiz class (so the questions need to be accessible).

我可以开始简单,只提出一个问题,让它工作并及时增加新的特点,但我认为,这样做是改进我对巴勒斯坦被占领土的理解的良好惯例,而且我担心,如果它发挥作用,而且我开始让人民检验它,我最终会结束其他方面的工作。 我希望能更好地构想我的项目,我认为,这可以成为改进这一计划的良好机会。

PS: In case it wasn t obvious, I am not a programmer by educational background :)

最佳回答

I ve got brief quiz applicationding on production = 存在不同类型的问题,有不同的行为(应该以不同的方式提出、回答和提出)。 问题的复杂性各不相同。

在我的情况中,最适当的解决办法是建立问题超级阶级,采用一些抽象的方法(也可以是接口)和不同的执行。 此外,根据一些投入,工厂还采用了不同的处理方法(工厂)。

Think, about your interface (common part) of your question and use factory pattern. There could be more complicated scenario, where you can find some advantages of using AbstractFactory or Builder patter.

在我简单的情况下,抽取接口就足够了。

问题回答

You could use an Abstract Factory to create factories that know how to create questions based on specific parameters.
As for the notification you could use Observer Pattern. Study them and see examples in the language of your preference

思考两点:

  1. What objects use Question objects? What do they need Questions to do? That is we talk about the Interface(s) of the Question.
  2. How do Questions do those things? The Behaviour of the Question.

最初,只想到会边。 我不明白我们需要做什么。 请允许我看到,回答自由写法的问题,以及提出“A至D号标书”的问题,以及提出“A至D号标书”的问题,在《国际倡议》中可能有很大不同。 因此,你想到的是“问题:请显示、回答和告诉我用户的分数”或“问题:你的案文是什么? 问题:你做了哪些回答? 问题:你的四项选择是什么? 问题:用户的分数是多少?”

一旦你明确提出问题的责任,你就可以考虑不同问题接口和类别的适当数目,从而决定你是否需要像工厂这样的创造模式。 当你拥有多个不同班级时,工厂运转良好。

工厂:让我提出一个问题。 问题:去问用户。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签