Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object-oriented or sequential?

Tags:

c++

oop

I'm refactoring a 500-lines of C++ code in main() for solving a differential equation. I'd like to encapsulate the big ideas of our solver into smaller functions (i.e. "SolvePotential(...)" instead of 50 lines of numerics code).

Should I code this sequentially with a bunch of functions taking very long parameters lists, such as:

int main(int *argc, void **argv){
   interpolate(x,y,z, x_interp, y_interp, z_interp, potential, &newPotential);
   compute_flux(x,y,z, &flux)
   compute_energy(x,y,z, &eng)
   ...
   // 10 other high-level function calls with long parameter lists
   ...
   return 0;
}    

Or should I create a "SolvePotential" class that would be called like so:

int main(int *argc, void **argv){
   potential = SolvePotential(nx, ny, nz, nOrder);
   potential.solve();
   return 0;
}

Where I would define functions in SolvePotential that uses member variables rather than long parameter lists, such as:

SolverPotential::solve(){
  SolvePotential::interpolate()
  SolverPotential::compute_flux()
  SolverPotential::compute_energy()
  // ... 
  //  10 other high-level function calls with NO parameter lists (just use private member variables)
}

In either case, I doubt I'll re-use the code very much... really, I'm just refactoring to help with code clarity down the road.

Maybe this is like arguing "Is it '12' or 'one dozen'?", but what do you think?

like image 466
Pete Avatar asked Nov 25 '08 19:11

Pete


Video Answer


1 Answers

Write it sequentially and then refactor if there's something you think you can reuse or would make it clearer.

Also, a SolvePotential class doesn't make a lot of sense since a class should be an Object with the method SolvePotential.

like image 106
Joe Phillips Avatar answered Sep 30 '22 06:09

Joe Phillips