Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How it help me two separate class in C++ instead of single class?

How it help me two separate class in C++ instead of single class?

Scheduled Pinned Locked Moved Solved General and Desktop
c++design patternc++11private
5 Posts 3 Posters 700 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yash001
    wrote on last edited by Yash001
    #1

    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; 
    }
    
    
    Pablo J. RoginaP kshegunovK 2 Replies Last reply
    0
    • Y Yash001

      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; 
      }
      
      
      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #3

      @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.

      Read and abide by the Qt Code of Conduct

      Y 1 Reply Last reply
      3
      • Y Yash001

        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; 
        }
        
        
        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #2

        @Yash001 you may want to read about opaque pointer technique or pimpl pattern

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        4
        • Y Yash001

          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; 
          }
          
          
          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #3

          @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.

          Read and abide by the Qt Code of Conduct

          Y 1 Reply Last reply
          3
          • kshegunovK kshegunov

            @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.

            Y Offline
            Y Offline
            Yash001
            wrote on last edited by
            #4

            @kshegunov @Pablo-J-Rogina Thank you for explanation.

            Pablo J. RoginaP 1 Reply Last reply
            0
            • Y Yash001

              @kshegunov @Pablo-J-Rogina Thank you for explanation.

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #5

              @Yash001 if your issue is solved (aside for the fact that you need to read and incorporate several concepts, I guess), please don't forget to mark this post as solved. Thanks.

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved