Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. to subclass or not to subclass...
Forum Updated to NodeBB v4.3 + New Features

to subclass or not to subclass...

Scheduled Pinned Locked Moved Solved Brainstorm
6 Posts 3 Posters 982 Views 2 Watching
  • 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    ...that is the question.

    My app controls a medium-sized (~100) pieces of equipment. Each equipment item can be classified into (exactly) one category; there are ~40 categories in an installation.

    I have a list model to maintain a list of equipment. This model is exposed to QML using the convention means.

    I'm considering the options for how to process each category of equipment. One option is to have a "super-category" which contains all of the properties of all the categories. This would be simple to implement, but has the drawback of creating a large class, whose data() and setData() functions will have to check for every property, possibly affecting performance. It will also be a relatively complicated class.

    The other option is to subclass each category. There are two drawbacks that I see to this approach:

    • this will entail a lot of coding, possibly with a fair amount of redundancy.

    • I'll have to implement the equipment item list as a list of pointers, with the associated risk of memory leaks.

    Neither of these options thrill me. I'd welcome opinions on which is the lesser of two evils, as well as any ideas for another way to do this.

    Thanks...

    JoeCFDJ 1 Reply Last reply
    0
    • mzimmersM mzimmers

      ...that is the question.

      My app controls a medium-sized (~100) pieces of equipment. Each equipment item can be classified into (exactly) one category; there are ~40 categories in an installation.

      I have a list model to maintain a list of equipment. This model is exposed to QML using the convention means.

      I'm considering the options for how to process each category of equipment. One option is to have a "super-category" which contains all of the properties of all the categories. This would be simple to implement, but has the drawback of creating a large class, whose data() and setData() functions will have to check for every property, possibly affecting performance. It will also be a relatively complicated class.

      The other option is to subclass each category. There are two drawbacks that I see to this approach:

      • this will entail a lot of coding, possibly with a fair amount of redundancy.

      • I'll have to implement the equipment item list as a list of pointers, with the associated risk of memory leaks.

      Neither of these options thrill me. I'd welcome opinions on which is the lesser of two evils, as well as any ideas for another way to do this.

      Thanks...

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @mzimmers the associated risk of memory leaks? ==> shared pointers may help.
      Is it possible to group categories with similar properties?

      mzimmersM 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @mzimmers the associated risk of memory leaks? ==> shared pointers may help.
        Is it possible to group categories with similar properties?

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @JoeCFD said in to subclass or not to subclass...:

        Is it possible to group categories with similar properties?
        This occurred to me, so I asked about it. It seems that trying to group the categories would result in ~30 groups, so it's not much help.

        I'm leaning towards the first option. It's going to create a huge class, and the data()/setData() functions are going to be quite large and/or complicated, which could be a mild performance issue, but overall it seems better (simpler) than subclassing and having to deal with each subclass in the model. Like I said, I'm not thrilled with either option.

        SGaistS 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @JoeCFD said in to subclass or not to subclass...:

          Is it possible to group categories with similar properties?
          This occurred to me, so I asked about it. It seems that trying to group the categories would result in ~30 groups, so it's not much help.

          I'm leaning towards the first option. It's going to create a huge class, and the data()/setData() functions are going to be quite large and/or complicated, which could be a mild performance issue, but overall it seems better (simpler) than subclassing and having to deal with each subclass in the model. Like I said, I'm not thrilled with either option.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @mzimmers hi,

          Did you also consider code generation ?
          If all your categories have a well defined structure, you could generate code out of it for you project. A bit like uic does out of XML.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          mzimmersM 1 Reply Last reply
          0
          • SGaistS SGaist

            @mzimmers hi,

            Did you also consider code generation ?
            If all your categories have a well defined structure, you could generate code out of it for you project. A bit like uic does out of XML.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @SGaist interesting suggestion, but probably not viable for this application.

            What I need is a way to break up the processing routine by category, which relies on multiple local variables. I guess I could create a function in the specialized class, and pass it all those local variables, but...that makes it seem like I need a subclass.

            I also considered a friend function within my model class, but I can't give it context without creating a lot of circular references.

            Aargh...I may not have a solution, but I'm certainly admiring the problem.

            mzimmersM 1 Reply Last reply
            0
            • mzimmersM mzimmers

              @SGaist interesting suggestion, but probably not viable for this application.

              What I need is a way to break up the processing routine by category, which relies on multiple local variables. I guess I could create a function in the specialized class, and pass it all those local variables, but...that makes it seem like I need a subclass.

              I also considered a friend function within my model class, but I can't give it context without creating a lot of circular references.

              Aargh...I may not have a solution, but I'm certainly admiring the problem.

              mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #6

              Just to close this out, I'm pursuing the subclass approach to this. Thanks for the suggestions.

              1 Reply Last reply
              0
              • mzimmersM mzimmers has marked this topic as solved on

              • Login

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