Thursday, July 9, 2009

Is it a good programming practice in C++ to include a class within another class?

Even if that within class is just a data class?

Is it a good programming practice in C++ to include a class within another class?
There's no problem with defining a class within a class if you wish to use this class only internally within the containing class and have no plans on exposing it to any other code.





If it's just data that doesn't need any special initialization or cleanup code, then it's probably not necessary to encapsulate them in a class.
Reply:you can do it waht ever way you want..or waht ever way the program demands..
Reply:Its up to the programer. If you find it easier to identify- go for it.
Reply:It happens a lot. In fact the object oriented world calls this "composition". For example, you can insert an engine class and a chasis class into a class called machine and the result can be made to repesent more machines easily.
Reply:it depends on the situation.


No comments:

Post a Comment