2

is there anybody who could give me some basic ideas about planning a concept of my c++ project?

I have a GUI with 2 line-edits , a button and a result-field. ( Later I want to have many line-edits for input and result but for now I want to keep it simple) My idea was to combine all my input-data in a new class ( class INPUT ) . For result I want to combine all result-data in another class ( class RESULT). For calculating the results I want to create a method (something like RESULT sum ( INPUT in ) ). I don`t want to do all of it in just 1 class, I need input and result classes because I will have many data-fields in the final version

Would this be a good concept? If so, where would I write the method of the calculation (sum()) ? In the INPUT class, the RESULT Class or the main.cpp ?

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
user3443063
  • 1,455
  • 4
  • 23
  • 37
  • You might want to check out the concept of [MVC (Model-View-Controller)](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller). – Ami Tavory May 08 '15 at 07:02

1 Answers1

0

Typically if you have this kind of input/output(or results) design, you want some third entity: an evaluator/operator kind of thing where you feed in the input and get the output as a result.

So if you want flexibility, I'd look at this as three entities, not two:

  1. input to encapsulate the user input.
  2. evaluator/operator which takes an input and outputs a result.
  3. result to encapsulate the computed result from the operator.

That'll give you three separate entities: one to focus on computation, and the other two to deal with representing data.

This is also common with nodal designs, like so:

enter image description here

That's a very flexible design, but suggests multiple relatively simple evaluators taking multiple simple inputs and outputs.

That might be overkill in your case if you just need one complex evaluator and one complex string input and output. But I'd still stick to this 3-entity/interface separation for a less monolithic/fussy design and a clear separation of responsibilities.