Monster Hunter
Monster Hunter

Reputation: 866

what is the correct class structure to use?

I'm writing a library that basically takes different information from multiple streams, assemble and matches them and send the matched result out. So I made 2 classes A, B and class C, D, E, F as builder classes for different final results.

Class A parses raw data from streams and organizes the data into blocks and pass to B and later on sends the final matched result out.

class A {
public:
   /* put data into structure and pass to B*/
   void parseStreamA(rawData);
   void parseStreamB(rawData);
   ...
   /* send final result out */
   void send();
}

Class B takes the block structure from A and tries to match it with other blocks it receives, then put matches blocks into structures C, D, E, F depends on the types of the blocks.

class B {
public:
   /* receives block and try to match to other blocks, put blocks into 
      corresponding structure C or D or E or F */
   void receiveBlock(block);
}

Class C, D, E, F ... takes multiple matches blocks and sends back to A if they have all the parts.

I could have done the following:

namespace n {
   class A {
      class B {
        class C{
        };
        class D{
        };
      };
   };
}

but I don't think it's a good idea. so I separate them to make flat classes. Now I have a bunch of data structure and methods to share between the classes but I don't want to put them into a header and attach to the classes because they will become global in namespace n. I don't want to wrap those structures and methods in a class either because it seems not proper to reference a structure as classX::structureY in my situation. Wrapping the classes in another namespace does not feel like a good idea either..I just want my class structure to be simple and scalable. How can I structure this?

Upvotes: 0

Views: 99

Answers (1)

Sinned Lolwut
Sinned Lolwut

Reputation: 182

You seem to be a bit confused. Have you looked at the class keywords public/private/internal etc?

I also suggest you to take a look at https://en.wikipedia.org/wiki/Single_responsibility_principle.

Without knowing the relation between the classes, we can't exactly help.

Upvotes: 2

Related Questions