Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. OOP and the scope of a class, am I wrong?

OOP and the scope of a class, am I wrong?

Scheduled Pinned Locked Moved The Lounge
designcomgraphicsiotquestion
79 Posts 45 Posters 2 Views 1 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.
  • H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #1

    My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

    K M L 0 Mike HankeyM 34 Replies Last reply
    0
    • H honey the codewitch

      My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      I'm not a OO person but it seams like TextFile.read() encapsulates much better what action is being performed on an instance of TextFile than TextFileRead which might be applied to some unknown object that may or may not support "read". Or worse, has subverted TextFileRead to do something totally unrelated, like open a can of beer. Maybe the Profs in question are confusing an interface with a class? Dunno. Seems wrong to me.

      Keep Calm and Carry On

      1 Reply Last reply
      0
      • H honey the codewitch

        My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

        M Offline
        M Offline
        MarkTJohnson
        wrote on last edited by
        #3

        Your take is the way I learned it. I thought it was the way Bjarne Stroustrup intended it.

        I’ve given up trying to be calm. However, I am open to feeling slightly less agitated. I’m begging you for the benefit of everyone, don’t be STUPID.

        pkfoxP 1 Reply Last reply
        0
        • H honey the codewitch

          My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Mixing (up) function(s) and actions. ReadTextFile is some clumsy rewording of a "TextReader" class.

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          H O 2 Replies Last reply
          0
          • L Lost User

            Mixing (up) function(s) and actions. ReadTextFile is some clumsy rewording of a "TextReader" class.

            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #5

            In this case it was part of an assignment to read phony medical records from a CSV. A more horrible name I could scarcely fathom. I was helping with their homework, and trying to teach them what their prof wasn't.

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            1 Reply Last reply
            0
            • H honey the codewitch

              My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

              0 Offline
              0 Offline
              0x01AA
              wrote on last edited by
              #6

              Personally I can't make a bridge between ReadTextFile and the car... Anyway you example shows a classic thing, that classes are usually not 'stand alone' and in a certain way 'connected'/'depended' Your examlpe: Engine.Start() does depend on the state of the Gear. Either Engine asks the gear for 'I'm ready to start' or the gear sends a message to the engine 'hey, I'm at gear 1 (without pressed clutch), not really good to start at the moment' and so on and on and on... Abstracting the reality is usually very hard. Only my two cents.

              H L D 3 Replies Last reply
              0
              • H honey the codewitch

                My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                Mike HankeyM Offline
                Mike HankeyM Offline
                Mike Hankey
                wrote on last edited by
                #7

                That's the way I learned it also, of course I taught myself but every reference I came across explained it that way.

                I don't think before I open my mouth, I like to be as surprised a everyone else. PartsBin an Electronics Part Organizer - Release Version 1.3.0 JaxCoder.com Latest Article: SimpleWizardUpdate

                1 Reply Last reply
                0
                • 0 0x01AA

                  Personally I can't make a bridge between ReadTextFile and the car... Anyway you example shows a classic thing, that classes are usually not 'stand alone' and in a certain way 'connected'/'depended' Your examlpe: Engine.Start() does depend on the state of the Gear. Either Engine asks the gear for 'I'm ready to start' or the gear sends a message to the engine 'hey, I'm at gear 1 (without pressed clutch), not really good to start at the moment' and so on and on and on... Abstracting the reality is usually very hard. Only my two cents.

                  H Offline
                  H Offline
                  honey the codewitch
                  wrote on last edited by
                  #8

                  Of course, but I was simplifying and glossing over details to simply get to the larger point, to wit: In my mind, a class is a noun, not a verb, essentially.

                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                  L G 2 Replies Last reply
                  0
                  • H honey the codewitch

                    My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

                    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                    M Offline
                    M Offline
                    Maximilien
                    wrote on last edited by
                    #9

                    It's complicated. :~

                    CI/CD = Continuous Impediment/Continuous Despair

                    1 Reply Last reply
                    0
                    • H honey the codewitch

                      Of course, but I was simplifying and glossing over details to simply get to the larger point, to wit: In my mind, a class is a noun, not a verb, essentially.

                      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      honey the codewitch wrote:

                      a class is a noun

                      Not really, since a class encapsulates properties (nouns), and actions (verbs); so it could be an ablative gerund.

                      0 1 Reply Last reply
                      0
                      • M MarkTJohnson

                        Your take is the way I learned it. I thought it was the way Bjarne Stroustrup intended it.

                        I’ve given up trying to be calm. However, I am open to feeling slightly less agitated. I’m begging you for the benefit of everyone, don’t be STUPID.

                        pkfoxP Offline
                        pkfoxP Offline
                        pkfox
                        wrote on last edited by
                        #11

                        He designed C++ not OOP

                        In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP

                        J M 2 Replies Last reply
                        0
                        • L Lost User

                          honey the codewitch wrote:

                          a class is a noun

                          Not really, since a class encapsulates properties (nouns), and actions (verbs); so it could be an ablative gerund.

                          0 Offline
                          0 Offline
                          0x01AA
                          wrote on last edited by
                          #12

                          Holy ... Dear Richard, you know me now for a longer time as an English non native. Can you please describe 'ablative gerund' in _very simple words_ for me? Thank you very much in advance ;)

                          J Greg UtasG L 3 Replies Last reply
                          0
                          • H honey the codewitch

                            My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

                            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                            R Offline
                            R Offline
                            raddevus
                            wrote on last edited by
                            #13

                            honey the codewitch wrote:

                            But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be.

                            This could be the beginning of a in-depth discussion on Communication. I have to parse the beginning of your sentence very closely and pull out "I'm hearing..." part. You are hearing that from a beginning student, I believe. Now, we can't be sure 1.if the Professors are actually teaching this (that a class is one action / functionality) 2. if it is the way the student is understanding it Let's say it is the latter ( choice 2 above). Now, that may simply mean that the Professor is teaching a concept poorly -- actually doesn't believe that a class is just one action but has somehow inadvertently used words that create a students understanding to be that. From what I remember about Professors and coding, it seems likely that the Professor is actually teaching OOP wrong. Few colleges have Professors which actually program or have been on large teams which have implemented large systems using OOP. However, I could also see that the student learning about OOP sees a simple example (because all University examples are far too simple (because anything large requires too much work on the Professor's part) and assumes that because there is only one functionality in the class along with a phrase the student has heard (Single Responsibility Principle) leads the student to believe that a class must have only one action. So, here we are back at the beginning. We don't know if: 1. The professor is wrong 2. the professor is confusing and the learning lands improperly 3. The student misunderstands on her own. We're down at the bottom, writhing in the Communication pain. :rolleyes: The best thing to do is: Redirect!! And that seems to be what you are doing. Tell the student the proper use of Classes and why they can have more actions. Good luck with Communication. I'm sure that I too have added some form of communication problem while writing this up. :laugh:

                            L H 2 Replies Last reply
                            0
                            • H honey the codewitch

                              My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

                              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                              J Offline
                              J Offline
                              jschell
                              wrote on last edited by
                              #14

                              honey the codewitch wrote:

                              But I'm hearing that professors are teaching that classes are effectively a single action

                              Plural? So someone claims that multiple different teachers are teaching that? And what professors? Community college? Some night school community education classes? High school?

                              honey the codewitch wrote:

                              Am I wrong here?

                              You are correct. But there could be more to it. For example the curriculum could be forced. Especially true for high school type education. They screw around all sorts of ways with teaching reading/math like that using experimental methods which never work. Or just an incompetent teacher. Either not trying or just one that does not have the knowledge.

                              H 1 Reply Last reply
                              0
                              • H honey the codewitch

                                My take: A class should group related data and actions that center around a single concept. A car class might contain 4 Tire class instances as data members, an Engine instance, and a Gearbox instance. Each one has actions relevant to its operation like Engine.Start(), and Wheel.Rotate() But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be. Am I wrong here?

                                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                D Offline
                                D Offline
                                dandy72
                                wrote on last edited by
                                #15

                                I used to work with a guy who did so much refactoring that most of his functions came down to one-liners, and all of his classes were focused to an extreme, to the point of being responsible for a single action. Looking at individual classes/functions one-by-one, his code became trivial to read, but the problem this introduced is that there were so many tiny single-purpose classes, the whole thing grew to have the opposite effect and became an unmanageable mess. He understood it very well. But the rest of the team spent way too much time jumping through endless class definitions, trying to find where the real work was being done. I'm hoping those professors aren't following that model.

                                L 1 Reply Last reply
                                0
                                • pkfoxP pkfox

                                  He designed C++ not OOP

                                  In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP

                                  J Offline
                                  J Offline
                                  jschell
                                  wrote on last edited by
                                  #16

                                  pkfox wrote:

                                  He designed C++ not OOP

                                  No one person "designed" OOP. Like many concepts it evolved over quite a long time with different people working on the concept. And at least when the "C++ Programming Language" was published for available books there were perhaps only four (or three) of them. And two were on C++. The concepts in all were basically the same.

                                  1 Reply Last reply
                                  0
                                  • 0 0x01AA

                                    Holy ... Dear Richard, you know me now for a longer time as an English non native. Can you please describe 'ablative gerund' in _very simple words_ for me? Thank you very much in advance ;)

                                    J Offline
                                    J Offline
                                    jschell
                                    wrote on last edited by
                                    #17

                                    lol Apparently it does mean something. I googled it just to be sure. But I still didn't understand what it means.

                                    0 1 Reply Last reply
                                    0
                                    • 0 0x01AA

                                      Personally I can't make a bridge between ReadTextFile and the car... Anyway you example shows a classic thing, that classes are usually not 'stand alone' and in a certain way 'connected'/'depended' Your examlpe: Engine.Start() does depend on the state of the Gear. Either Engine asks the gear for 'I'm ready to start' or the gear sends a message to the engine 'hey, I'm at gear 1 (without pressed clutch), not really good to start at the moment' and so on and on and on... Abstracting the reality is usually very hard. Only my two cents.

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #18

                                      An engine on a stand doesn't need a gear box to "start" or "run". It needs fuel and / or a battery. "Moving" is accomplished through the addition of a transmission, axels and wheels.

                                      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                                      1 Reply Last reply
                                      0
                                      • R raddevus

                                        honey the codewitch wrote:

                                        But I'm hearing that professors are teaching that classes are effectively a single action like ReadTextFile and it makes me a lot more irritated than I probably should be.

                                        This could be the beginning of a in-depth discussion on Communication. I have to parse the beginning of your sentence very closely and pull out "I'm hearing..." part. You are hearing that from a beginning student, I believe. Now, we can't be sure 1.if the Professors are actually teaching this (that a class is one action / functionality) 2. if it is the way the student is understanding it Let's say it is the latter ( choice 2 above). Now, that may simply mean that the Professor is teaching a concept poorly -- actually doesn't believe that a class is just one action but has somehow inadvertently used words that create a students understanding to be that. From what I remember about Professors and coding, it seems likely that the Professor is actually teaching OOP wrong. Few colleges have Professors which actually program or have been on large teams which have implemented large systems using OOP. However, I could also see that the student learning about OOP sees a simple example (because all University examples are far too simple (because anything large requires too much work on the Professor's part) and assumes that because there is only one functionality in the class along with a phrase the student has heard (Single Responsibility Principle) leads the student to believe that a class must have only one action. So, here we are back at the beginning. We don't know if: 1. The professor is wrong 2. the professor is confusing and the learning lands improperly 3. The student misunderstands on her own. We're down at the bottom, writhing in the Communication pain. :rolleyes: The best thing to do is: Redirect!! And that seems to be what you are doing. Tell the student the proper use of Classes and why they can have more actions. Good luck with Communication. I'm sure that I too have added some form of communication problem while writing this up. :laugh:

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #19

                                        Maybe the student is wresting with "code blocks" or "delegates": methods as "objects" (of "anonymous" classes). Or at least it would be fun to drop that on them. I was over the moon when I first discovered Clipper "code blocks" (DI before DI).

                                        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                                        1 Reply Last reply
                                        0
                                        • D dandy72

                                          I used to work with a guy who did so much refactoring that most of his functions came down to one-liners, and all of his classes were focused to an extreme, to the point of being responsible for a single action. Looking at individual classes/functions one-by-one, his code became trivial to read, but the problem this introduced is that there were so many tiny single-purpose classes, the whole thing grew to have the opposite effect and became an unmanageable mess. He understood it very well. But the rest of the team spent way too much time jumping through endless class definitions, trying to find where the real work was being done. I'm hoping those professors aren't following that model.

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #20

                                          In that case, if you make them all static, put them in related "class libraries", it becomes manageable; like "System.Math".

                                          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups