CSCI 3132 - Refactoring, Copy Control in C++ - A4


  • 作业标题:CSCI 3132 - Refactoring, Copy Control in C++
  • 课程名称:Dalhouse University CSCI 3132 Object Orientation and Generic Programming
  • 完成周期:2天

You work for an educational software company that is developing a suite of simple physics simulations. The code in Pendulum.cpp is the beginning of a suite intended to permit the creation of a series of different types of pendulum simulation.

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). You previously identified a code smell (“trivial layer”) in the AbstractEarthPendulum class but figured it was mostly harmless— until now.

Review the code and run the main routine to see the expected behaviour.
。。。

Part A: Refactoring

  1. (Refactoring step 1) Apply the refactoring approach “Collapse Hierarchy” to reduce the
    hierarchy levels by one. Ensure that the main routine still works as expected. Put a copy of the
    code in a folder called “RefactoringStep1”

  2. (Refactoring step 2) Next, use the Strategy design pattern (generic class diagram for the
    pattern is shown below) to replace the field g with a reference to a strategy object (as outlined
    below). This will allow different gravity models to be dynamically associated with a Pendulum
    instance.

。。。

Part B: Copy Control

Now that pendulums are more configurable, copying pendulums could be very useful. For
example, one might set up a pendulum on Earth with a given string length and point mass,
make ten copies, and update the initial angular displacements to hold different values before
letting them all swing in parallel.

You realize that you now should think a bit more about copy control for pendulum objects.
RegularPendulum objects maintain a history of displacement and velocity values that grows
very large as a simulation progresses, so you must be careful about managing this. You decide
on the following rules:

Marking Scheme (/20)

2 Refactoring step 1 completed correctly
1 Main routine outputs the same values after refactoring step 1.
3 Refactoring step 2 completed correctly
1 Main routine outputs the same values after refactoring step 2.
3 New test function for GravityConstant implemented as specified.
2 Copy constructor(s) and assignment operator(s) correctly implemented where required.
2 Move constructor(s) and assignment operator(s) correctly implemented where required.
1 Destructor(s) correctly implemented where required.
1 No unnecessary copy control methods are implemented.
4 Test functions provided for new copy control functionality; test functions adequately
test copy control rules.

Completing the bonus provides up to 4 marks – anything above 20 will be incorporated into your final assignment mark


文章作者: IT神助攻
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 IT神助攻 !
  目录