How it help me two separate class in C++ instead of single class?
-
Just for learning purpose I am posting this question.
What are the benefit we will get if we create separate class for private variable instead of create variable inside the private area?
for example 1:
class Framewidget{ private: int tabnumber; QString buttonName; }
what are the benefits I will get if I will create the class like below. Is it any design pattern?
which logic goes to FramewidgetPrivate? and which logic I need to put in Framewidget?class FramewidgetPrivate; class Framewidget{ private: class FramewidgetPrivate QScopedPointer<FramewidgetPrivate> d; // object is created inside initializer list } class FramewidgetPrivate { public: int tabnumber; QString buttonName; }
-
@Yash001 said in How it help me two separate class in C++ instead of single class?:
What are the benefit we will get if we create separate class for private variable instead of create variable inside the private area?
Binary compatibility. The size of the objects of said class don't change when you add or remove a member variable.
what are the benefits I will get if I will create the class like below. Is it any design pattern?
Yes, see @Pablo-J-Rogina's links.
which logic goes to FramewidgetPrivate? and which logic I need to put in Framewidget?
Public API goes into the public class, while private API most often goes into the private class.
-
@Yash001 you may want to read about opaque pointer technique or pimpl pattern
-
@Yash001 said in How it help me two separate class in C++ instead of single class?:
What are the benefit we will get if we create separate class for private variable instead of create variable inside the private area?
Binary compatibility. The size of the objects of said class don't change when you add or remove a member variable.
what are the benefits I will get if I will create the class like below. Is it any design pattern?
Yes, see @Pablo-J-Rogina's links.
which logic goes to FramewidgetPrivate? and which logic I need to put in Framewidget?
Public API goes into the public class, while private API most often goes into the private class.
-
@kshegunov @Pablo-J-Rogina Thank you for explanation.