ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Assignment 4: Refactoring and Patterns

2019-06-25 20:01:54  阅读:295  来源: 互联网

标签:code GravityModel pendulum Patterns Assignment will Refactoring routine test



Assignment 4: Refactoring and Patterns
You work for an educational software company that is developing a suite of simple Physics
simulations. The code in pendulum.zip is the beginning of a suite intended to permit the creation of
a series of different types of pendulum simulation. You previously identified a code smell (“trivial
layer”) in the AbstractEarthPendulum class, but figured it was mostly harmless. Now your
team wants to be able to dynamically set which planet a pendulum is on during an interactive
simulation, and to allow different kinds of gravity models that are impossible to represent with a
single constant (e.g., latitude models).
1. Run the main/test routine to see the expected behavior of the code.
2. Apply the refactoring approach “Collapse Hierarchy” to reduce the hierarchy levels by one.
Ensure that the main/test routine still works as expected. Make a copy of all the code in a folder
called “RefactoringStep1”
3. Next, use the Strategy design pattern (shown below) to replace the field g with a reference to a
strategy object (as outlined below). This will allow different kinds of gravity models to be associated
with a Pendulum instance dynamically.
Name the strategy interface GravityModel, with a single method
public double getGravitationalField ();
Assume that objects implementing GravityModel will be initialized with all state required to
produce the gravitational field value under their specific model, and that this occurs before being
assigned to a pendulum. In other words, the pendulums will just use the model assigned to it via the
GravityModel interface. Adjust the pendulum constructors so that a GravityModel is
assigned on initialization, and add a new method that will allow the GravityModel to be changed
dynamically.
Define one concrete strategy called GravityConstant. This class simply receives a constant
value for g in its constructor.
4. Run the main/test routine to ensure that the functionality hasn’t changed. Copy all the code into a

Patterns留学生作业代做、代做Collapse Hierarchy作业、代写c/c++,Python
folder called “RefactoringStep2”
5. Modify the provided main/test routine so that it initializes a SimplePendulum and a
RegularPendulum with a GravityConstant object, lets the pendulums swing for a little
while, then assigns a different GravityConstant object. For example, your first
GravityConstant could represent the Earth’s gravitational field (9.81 m/s^2), and the second
could represent Jupiter’s (25 m/s^2).
Submit all code (including the 2 refactoring folders and the final version of the code with the
modified test) as a single zip file on Brightspace.
Marking Scheme for A4 (20 marks):
Rubric for A4 is not provided prior to the deadline.

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com 

微信:codehelp

标签:code,GravityModel,pendulum,Patterns,Assignment,will,Refactoring,routine,test
来源: https://www.cnblogs.com/linta/p/11085008.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有