Question : How to program well

I have design/ideologic problem, and don know what solution choose.

ClassWithData - is class that store data for ClassWithFunction
ClassWithFunction - is class that do something by calling its function

class A
{
      ClassWithData cd;
      ClassWithFunction cf;
private:
      RunWrapper()
      {
            cf.function(cd);            
      }
};

OR

class A
{
      ClassWithData cd;
      ClassWithFunction cf;
private:
      RunWrapper(ClassWithData& x)
      {
            cf.function(x);            
      }
};

(RunWrapper is ofcourse private)
Iam confused with that becouse, sometimes i write like in first example and sometimes a like second without any reson.

Answer : How to program well

Ok I see, thanks for posting the headers. :)

This code is clearly overcomplicating things, actually its only 1 class needed, rather than 3.

Lets call it "Process":

class Process
{
public:
    Process(std::wstring executable_name_, std::wstring command_line_);
    ~Process(void);

    void StartProcess();

private:
    void CreateProcessAsActiveSession();
    bool GetActoveConsoleSessionId(DWORD& session_id);

private:
    std::wstring executable_name_;
    std::wstring command_line_;
};

The member-function "StartProcess" belongs into this class, because all it needs in terms of data, is here.

You see it has all the functionality, as the 3 classes, but it encapsulates the data and the functions that operate on that data in 1 place. That is what is meant by "Encapsulation" in terms of OO-Programming.
Plus it has a cleaner interface and is easier to use.

Maybe it makes it clearer, if you think about adding new functionalities, like KillProcess and others, they all belong into this class. Keep the data and the functions that operate on that data together in 1 place.
Random Solutions  
 
programming4us programming4us