需要一些外部建议来设计这个类图!
摘要
我必须对用 FORTRAN 编写的应用程序进行现代化改造,简而言之,它负责多年来的人口预测。因此,我有一个初始人口作为输入。这个初始人口是按年龄分类的,即每年所有数字的总和就是今年的总人口。
让我们花几秒钟看一下数据。
Year: 2009
Age 0: 43786.0000
Age 1: 42997.0000
Age 2: 42656.0000
...
Age 99: 2439.0000
然后,我们必须按照与上述初始人口相同的方式设定的特定死亡率来预测 2010 年,只不过它包括死亡率而不是每岁的总数。
Year: 2009
Age 0: 0.000213345
Age 1: 0.000212543
Age 2: 0.000201938
...
Age 99: 0.04824421
Age 106: 0.50000000
这个想法是将这些实体分组到类中。我已经设计了一个,我想知道是否可以在某些方面进行改进。
目标
简化设计并将统计计算嵌入到对象类中,以便在需要时更容易测试和模拟。
实际类图
我觉得它还可以改进。为了您的信息和便于阅读,下面是该图中使用的法语术语的索引:
TauxFeconditeAnnuel -> Annual Fecondity Rate
TauxMortaliteAnnuelle -> Annual Death Rate
PopulationAnnuelle -> Annual Population
SoldeMigratoireAnnuel -> Annual Net Migration
StatistiqueAnnuelle -> Annual Statistic
StatistiqueAnnuelleParSexe -> Annuel Statistic per Sex
我的思考是关于是否在 PopulationAnnuelle 类中包含 Death Rate 类实例。有初始人口年份和未来 96 年预测的死亡率。此外,每年的人口必须有其死亡率,而每年的人口不一定存在,我才能有今年的死亡率。
假设我有 2009 年的初始人口,直到 2105 年我才预测 2010 年、2011 年、2012 年等的人口。然而,我有所有这些年的死亡率预测,人口增长基于这些死亡率率来确定哪些人口仍然活着,以及我们有多少人死亡,等等。
我想将 PopulationAnnuelle 类作为我的模型的基类,尽管我觉得StatistiqueAnnuelle 更适合这项工作,然后让 PopulationAnnuelle 继承它。
问题
- 您对我的担忧有何看法?
- 根据我希望实现的目标,最好的设计是什么?
- 我是否应该使用 StatistiqueAnnuelle 作为基类/接口,并让其他类(如 TauxMortalite、PopulationAnnuelle 等)从它派生,有点像现在设计的那样?
任何可以接受的想法都将由我个人投票。最准确和有帮助的答案将被接受作为我的问题的答案。
感谢您的善意帮助和支持! =)
您能为我们确定常见的重要用例/场景吗? (阿德里安·K)
一个常见的可能用例/场景是根据人口增长来规划养老金计划的需求。 “预测”人数后,您可以计算出将参加养老金计划的人数和将退休的人数,然后估算出缴纳者需要支付的资金需求,以便养老金计划资金有足够的钱在他们退休后支付养老金等。
另一种可能的常见情况是保险公司。根据人口增长,有关保险使用情况的统计数据将使公司能够预测其资金来源的需求,并根据事故退款与每个年龄的每月输入付款来确定给定保险金额的每月付款,例如汽车保险。
这种做法称为估值。
Summary
I have to modernize an application written in FORTRAN that, in short, is responsible for demographic projections through years. As such, I have an initial population given as an input. This initial population is categorized by years of age, that is, the sum of all numbers per year of age represents the total population for this year.
Let's take a look on data for a few seconds.
Year: 2009
Age 0: 43786.0000
Age 1: 42997.0000
Age 2: 42656.0000
...
Age 99: 2439.0000
Then, we have to project year 2010 according to certain death rate set the same way as this above-mentioned initial population, except that it includes rates instead of totals per year of age.
Year: 2009
Age 0: 0.000213345
Age 1: 0.000212543
Age 2: 0.000201938
...
Age 99: 0.04824421
Age 106: 0.50000000
The idea is to group these entities under classes. I have already designed one, and I wonder whether it could be improved in some ways.
Objective
To simplify design and to embed statistical calculations within object classes so that it is more easily testable and mockable when required.
Actual Class Diagram
I feel like it can be improved. For your information and ease of readability, here's a index of the French terms used in the diagram:
TauxFeconditeAnnuel -> Annual Fecondity Rate
TauxMortaliteAnnuelle -> Annual Death Rate
PopulationAnnuelle -> Annual Population
SoldeMigratoireAnnuel -> Annual Net Migration
StatistiqueAnnuelle -> Annual Statistic
StatistiqueAnnuelleParSexe -> Annuel Statistic per Sex
My reflections are about whether or not to include a Death Rate class instance within a PopulationAnnuelle class. There exist death rates for initial population year and the next 96 years of projection. Besides, an annual population has to have its death rate, and an annual population is not obliged to exist for me to have a death rate for this year.
Let's say I have the initial population for 2009, I have not yet projected population for 2010, 2011, 2012, etc. until year 2105. Yet, I have death rate projections for all of these years, and population growth is based on these mortality rates to determine what population remain alive, and how many deaths we got, etc.
I thought of putting the PopulationAnnuelle class as the base class for my model, though I feel like StatistiqueAnnuelle is more suitable for the job, then making PopulationAnnuelle inherit from it.
Questions
- What are your thoughts on the about my concerns?
- What is the best design based on what I wish to accomplish?
- Should I use StatistiqueAnnuelle as the base class/interface and make the others like TauxMortalite, PopulationAnnuelle, etc. derive from it, a bit like it is now designed?
Any acceptable thoughts will be upvoted personally by me. The most accurate and helping answer will be accepted as the answer to my question.
Thanks for your kind help and support! =)
Are you able to identify for us the common significant use cases / scenarios? (Adrian K)
A common possible use case/scenario would be to plan the needs for pension plans based upon population growth. After the amount of people has been "predicted", you may calculate the number of persons who will contribute to the pension plan and the people who will retire, then estimate the funding needs the contributors will need to pay so that the pension plan funds will have enough money to pay the pensions for them later when they retire and so forth.
Another possible common scenario would be insurances company. Based on population growth, statistics about the insurance usage would allow the company to predict the needs of their funding sources and establish the monthly payment for a given coverage amount based on accident refunds versus input monthly payments per age, let's say for car insurance for instance.
This exercise is called valuation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些初步的想法:
在我看来,死亡率是一个更广泛概念(死亡率?)的子类——对数据的修正或影响;出于这个原因,我可能不会明确地将其包含在 PopulationAnnuelle 中。另一种观点是将人口数据传递到“比率”修饰符中,而不是将其嵌入到人口中。
是的 - 只是想清楚 - 我认为你会希望尽可能清晰地分离你的担忧。这就是为什么我询问您需要满足的重要场景 - 例如,我可以看到您希望使用 PopulationAnnuelle 做很多事情,其中死亡率是不需要的,甚至是可取的。
更新
嗯 - 为什么?需要考虑两件事...首先,您是否 100% 确定在应用程序的生命周期中您只需要以年为单位进行处理?将一年的概念如此大量地构建到代码中并不是您想要轻易做的事情。
其次,我完全明白年度统计数据包括死亡人数和总人口的逻辑想法 - 但我不确定你是否会通过继承在类结构中反映这一点(?)(并不是说你不能 - 你已经花了很多时间比我思考这个问题的时间更长)。除了反映特定的心态之外,继承实际上给了你什么(以及它会对你做什么)?
这听起来很可疑:一个类被要求生成它自己的一个新的不同实例。我可能有一个类/组件“TrendPredictor”(?),它传递了它需要的所有数据(或对数据集的引用)并返回了一些对象。如果您想对此执行更多趋势预测,那么我想传入和传出相同的类型是有意义的,因此很容易以任何组合将操作串在一起。
我要做出的唯一的其他补偿是,我会看到这些输入和输出非常愚蠢(因此不需要太多(如果有的话)继承 - 它们听起来更像是数据结构,而不是提供丰富功能的类。
Some initial thoughts:
A death rate seems to me to be a sub-class of a broader concept (rate?) - a modifier or influence on the data; for that reason I would probably not explicitly include it in the PopulationAnnuelle. An alternative view would be to have population data passed into a "rate" modifier rather than embedding it in the population.
Yes - just thinking it through - I think you'd want to keep your concerns as cleanly separated as possible. This is why I asked about the significant scenarios you need to cater for - for example I can see you wanting to do lots of things with the PopulationAnnuelle where the death rate is not needed or even desirable.
Update
Hmmm - why? Two things to consider... Firstly, are you 100% certain that for the life of the application you'll only ever need to deal in units of years? Building the concept of a year so heavily into the code isn't something you'd want to do lightly.
Secondly, I totally get the logical idea that yearly statistics include deaths and a total population - but I'm not sure you'd reflect that in class structure via inheritance (?) (Not saying you can't - you've spent way longer thinking about this than I have). Apart from reflecting a particular mindset what does the inheritance actually give you (vs what will it do to you)?
That sounds dubious: a class is asked to produce a new different instance of itself. I'd probably have a class / component "TrendPredictor" (?) that was passed in all the data it needed (or references to sets of data) and returned some object. If you then wanted to perform more trend prediction on that then I guess it would make sense to pass the same types in and out so it was easy to string operations together in any combination.
Th eonly other commpent I'd make is that I woudl see those input and outputs being pretty dumb (and therefore not needing much (if any) inheritance - they sound more like data structures than classes that offer rich functionality.