Sharing classes
Posted: Mon Nov 03, 2008 4:58 pm
I would like to know your opinion about the following problem:
There are 2 classes, say we class A and class B. I need to use object of class A inside the class B. Most important for me is usability and flexibility of the code. For example I don't think that implementation like create objects A and B in the main program and then use object A inside class B as global variable is good practice. So two ways come to my mind - 1) pass the object A into the constructor of class B or 2) include class A definition in the file where class B is defined and create instance in the constructor of class B. What is the best implementing practice? Is there any other better solution?
Thanks
There are 2 classes, say we class A and class B. I need to use object of class A inside the class B. Most important for me is usability and flexibility of the code. For example I don't think that implementation like create objects A and B in the main program and then use object A inside class B as global variable is good practice. So two ways come to my mind - 1) pass the object A into the constructor of class B or 2) include class A definition in the file where class B is defined and create instance in the constructor of class B. What is the best implementing practice? Is there any other better solution?
Thanks