Forum Moderators: open

Message Too Old, No Replies

When to create classes in C++

         

hb code for life

7:46 pm on May 2, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



Is there any kind of rules or a guide to when should I create classes?

I am doing a school assignment in where I create a basic company workers management system.

I input the data of the workers and save them on a file, and use them all over the program.

I have some functions that I have to write like, inputWorkersDataAndSaveToFile(), readFromFileAndPrintWorkersData(), sortAndPrint, diplayWorkersWithSalariesAbove, and a few more.

So it got me wondering, should I create a class and group all these functions together since they are all related? Would it be necessary since I am going to use only one instance of the class ever?

Worth noting that I want create a vector that hold all the workers data and plan using that vector in multiple functions. One reason I started thinking about creating a class is that I am trying to avoid using global variables.

So my program would have two classes
class Worker
and
class Manager


Should I create a class in this scenario? Also, is there any rule of thumbs to when to create classes.
I have searched about this topic but didn't find much.

My question really falls back on how to design things.

Thanks