Level of abstraction

Hi there,

I have a few questions related to the level of abstraction.

Is there any logic behind the way, how we’re separating things between main.cpp and our class? Basically, I see our FBullAndCow game as a whole, which includes intro output, guess input and so on (because this is a part of our BullAndCow game). I’m just confused and it feels like I’m thinking in the wrong way.

Why main.cpp has some methods, instead of moving those methods to the separate classes/class? This is done on purpose (this is how it should look like?) or it’s just for the learning?

I will really appreciate if any explanations will be provided.

Anything that is dealing with the isogram, counting of bulls and cows, and any of their helper functions are being created in the FBullCowGame class and things that are used to display or get input from the user (a view) is being defined in main.

The idea behind it is that you could just re-use the code in the FBullCowGame class for other libraries or APIs (like Unreal) without changing much, if anything.

1 Like

Hey @DanM,

Thanks for the reply.
I was aware of your explanation and unfortunately, it doesn’t explain much.

Do you or anyone else have any idea why the things that are used to display or get input from the user is being defined in the main instead of separate class/library? Some design pattern is used or this is just a random idea?

Well they aren’t in a class because they aren’t really related to each other in any way. You could put them in a seperate file however there’s only 5 rather short functions. So I don’t see the need to do that really.

Still, this seems soo weird… If at some point we’ll add some additional functions for the input/output logic, then it would make sense to move all the functions to the separate class !?

In such case, it also makes sense to create such class from the beginning in order to have a flexibility for the future updates (possibly I’m wrong because I have no idea about game design).

How do you envision this class looking? What are you trying to encapsulate?

Also sorry for the late response, I looked at this before I went to bed on the day you posted this and forgot about it and since I read the update it didn’t have the blue dot next to it when I looked at the Unreal section the next day.

Hey @DanM,

I was just wondering why input/output (I/O) functions are not moved to the separate class, and I wanted to encapsulate those functions, so only that class would be responsible for the I/O operations.

I’ve implemented such class for myself, but during the implementation, I’ve realized that it is pretty complicated to implement such class without using references and pointers, basically because those 2 classes should reference to each other :slight_smile: e.g. FBullCowGame will call some methods of FBullCowGameIO class, but FBullCowGameIO should also reference to the FBullCowGame in order to get some dynamic data: current try for example.

So for simplicity, it is wise to use I/O functions in the main.cpp file :slight_smile: because otherwise, newcomers may run away seeing references and pointers in action at this learning point :smiley:

Anyway, thank you for your replies I really appreciate it.

My point still stands; there’s no data to encapsulate. What data will be private? Think of the C++ Standard Library. None of the algorithms (std::sort, std::find etc.) are in a class, neither are std::cout, std::cin, std::getline because there’s no data to encapsulate, it’s just a function. (or variable)

Can’t argue, because you’re right :slight_smile: