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 4 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.
  • J jochance

    Sounds like someone misunderstood. Those will be some messed up students if they come out thinking classes are/should be SRP. Methods/functions sure, but... OOP tends to be highly overrated when you turn on the ultra pedant. Probably through here, I've read recent articles from others who spit on DRY and recognize that classic OOP has some serious faults.

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

    The directive in the assignment, which I had a copy of said literally name the class ReadTextFile.

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

    J J 2 Replies Last reply
    0
    • G Gary Wheeler

      honey the codewitch wrote:

      In my mind, a class is a noun, not a verb, essentially

      For me, a class may be either a noun or a verb. As a noun, the concept represented by the class is a thing, and the class provides information and operations for that thing. For a verb the concept is a process, and the class supports that process. I guess 'process' can be thought of as a noun, but thinking of it that way adds indirection to my thinking.

      Software Zen: delete this;

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

      That's a good point. I was trying to get to the essence of it and simplify, but obviously I missed the mark in terms of covering every eventuality.

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

      J 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

        S Offline
        S Offline
        Steve Naidamast
        wrote on last edited by
        #59

        I always split my OOP classes into two parts; classes for actions, and structures\structs for data. I just find it easier that way. I also try to limit what each would hold in the attempt to keep my classes\structures small. In the end, OOP's big advantage is its organizational capabilities within an application. And that organization is primarily up to the developer, not a professor...

        Steve Naidamast Sr. Software Engineer Black Falcon Software, Inc. blackfalconsoftware@outlook.com

        1 Reply Last reply
        0
        • H honey the codewitch

          The directive in the assignment, which I had a copy of said literally name the class ReadTextFile.

          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
          jochance
          wrote on last edited by
          #60

          #AdmiralAckbar It's a trap! Hopefully... he's gonna angle that into ok, that was a good start, but... sorta thing.

          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

            M Offline
            M Offline
            megaadam
            wrote on last edited by
            #61

            The only reasonable thing I think the professor could have referred to is what Gerry Schmitz above (~3rd from top) referred to class TextReader which is not insane in the terms of GOF (Design Patterns) but Prof's way of describing it is ofc misleading. e.g.

            class PngReader : public ImageReader {...

            class SvgReader : public ImageReader { ...

            "If we don't change direction, we'll end up where we're going"

            H 1 Reply Last reply
            0
            • M megaadam

              The only reasonable thing I think the professor could have referred to is what Gerry Schmitz above (~3rd from top) referred to class TextReader which is not insane in the terms of GOF (Design Patterns) but Prof's way of describing it is ofc misleading. e.g.

              class PngReader : public ImageReader {...

              class SvgReader : public ImageReader { ...

              "If we don't change direction, we'll end up where we're going"

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

              Yeah, and this could have also been CsvReader except it only read a specific CSV with certain columns and datatypes. ReadTextFile is maybe the worst name I could think of for that. =) PatientDataReader would have been better.

              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
              • J jochance

                #AdmiralAckbar It's a trap! Hopefully... he's gonna angle that into ok, that was a good start, but... sorta thing.

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

                I explained that while he should do as the assignment requires, a class encapsulates related data and actions, so it really was an inappropriate name for a class. I suggested another name "PatientDataReader" or something (I forget exactly, but it was better) if he was doing it on his own.

                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

                  M Offline
                  M Offline
                  MSBassSinger
                  wrote on last edited by
                  #64

                  You are right. A class should represent some definable entity, whether atomically (e.g. Tire class) or in the aggregate of related entities (Car class that inherits Vehicle class, containing a Tire class collection, Engine class, Transmission class, etc.). Whatever "professors" that are saying what you report need to go get their hands dirty writing and supporting production software to test their theories before opening their mouths to sound foolish.

                  1 Reply Last reply
                  0
                  • M Member_5893260

                    Well, at least we'll never be unemployed!

                    A Offline
                    A Offline
                    Andreas Mertens
                    wrote on last edited by
                    #65

                    You are right - someone will have to come along afterwards and clean this all up... :doh:

                    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

                      S Offline
                      S Offline
                      StatementTerminator
                      wrote on last edited by
                      #66

                      honey the codewitch wrote:

                      professors are teaching that classes are effectively a single action

                      That sounds like a method, not a class. Or a class with one method, which smells funny. Factoring OO is something that's taught in school, but not really understood until you get experience with it. Judgment calls have to be made. I've had to work with OO code that broke everything down into atomic classes. It was a nightmare to trace the code, and imagine what that does to the stack.

                      H 1 Reply Last reply
                      0
                      • S StatementTerminator

                        honey the codewitch wrote:

                        professors are teaching that classes are effectively a single action

                        That sounds like a method, not a class. Or a class with one method, which smells funny. Factoring OO is something that's taught in school, but not really understood until you get experience with it. Judgment calls have to be made. I've had to work with OO code that broke everything down into atomic classes. It was a nightmare to trace the code, and imagine what that does to the stack.

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

                        StatementTerminator wrote:

                        I've had to work with OO code that broke everything down into atomic classes.

                        To me that seems quite common these days in enterprise apps, almost as though someone made it by creating one extremely detailed UML diagram and then generating code from that. I've even seen many projects posted here that seem to overly factor. It does make it a nightmare to trace. I usually can't make much sense of code that's overly factored.

                        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
                        • L Lost User

                          Ha ha! I remember "ablative" and "gerund" from my Latin classes back in the 1950s. So I just put the two words together as a joke. But the joke, it appears, is on me, as there realy is such a thing. But I am not sure exactly what that thing is.

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

                          LOL. So I am not the only one.

                          1 Reply Last reply
                          0
                          • D Daniel Pfeffer

                            [Gerund and Gerundive | Dickinson College Commentaries](https://dcc.dickinson.edu/grammar/latin/gerund-and-gerundive#:~:text=The ablative of the gerund,%2C and (rarely) prō.)

                            Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

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

                            I think I would rather read a PHD research article on string theory.

                            1 Reply Last reply
                            0
                            • H honey the codewitch

                              That's a good point. I was trying to get to the essence of it and simplify, but obviously I missed the mark in terms of covering every eventuality.

                              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
                              #70

                              Keeping in mind of course that a school class is intended to teach concepts not practice. So in general one can think of it as a noun but if someone insists that every single class must always follow some rule about that then it is going to be a problem.

                              1 Reply Last reply
                              0
                              • H honey the codewitch

                                Yeah plural, as I've seen before in other assignments in the past. CS coursework, last one at a uni in south africa.

                                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
                                #71

                                Perhaps the classes were really about teaching coding (mostly) and not about concepts? True it shouldn't be that way but it does happen.

                                1 Reply Last reply
                                0
                                • M Mark Quennell

                                  I guess that could be considered a class in a command-based architecture, where ReadTextFile inherits from (or implements) some sort of base Command class and it contains all the information the processing system needs to perform that action, but it's a stretch, and certainly not to be taught as "the norm"...

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

                                  Mark Quennell wrote:

                                  where ReadTextFile inherits from (or implements) some sort of base Command class

                                  Interesting possibility. Although then either the class should be an advanced one or specifically about patterns. Patterns should not be introduced in an introductory course.

                                  1 Reply Last reply
                                  0
                                  • D Daniel Anderson 2021

                                    I`d say no you are not wrong, but the teacher is not necessarily wrong either. A class can be almost anything in C++. - Can be an interface - Can be a functor - Can be just data - Whatever... so, depending on how the teacher wants the thing to evolve he might direct his students. with very little or no context it is hard to decide who's right. If you are using class to model things, they can be names. If they model actions, they can be verbs. If they model attributes, they can be adjectives. classes are one of the mechanisms for encapsulation & data hiding after that, when I do code review, I usually check the coupling between the class and the client, this usually tells me if the data hiding or encapsulation is at a proper level or done right.

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

                                    Daniel Anderson 2021 wrote:

                                    but the teacher is not necessarily wrong either

                                    The teacher is wrong if the class is supposed to be an introduction of some sort. Especially if one is attempting to explain 'class' and 'methods'. One should not introduce advanced concepts until students have at least had the chance to master basics.

                                    1 Reply Last reply
                                    0
                                    • H honey the codewitch

                                      The directive in the assignment, which I had a copy of said literally name the class ReadTextFile.

                                      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
                                      #74

                                      So then hypothetically and because you said elsewhere that it was copied... See the following. https://www.chegg.com/homework-help/questions-and-answers/using-java-programming-techniques-presented-fig-156-readtextfilejava-chapter-15-presentati-q57099852[^] In that there is nothing wrong with the 'class' being defined that way. Because it is main class in java. It is not a OO class but rather a specific type of java class. There appear to be other examples. I used the following to google.

                                      programming assignment "class ReadTextFile"

                                      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

                                        T Offline
                                        T Offline
                                        Tiger12506
                                        wrote on last edited by
                                        #75

                                        I would say that you are 100% correct. The weirdness started when languages and frameworks started making unreasonable demands of the analogy. Take, for instance, Java's everything is a class, even when it's not.. or the concept of microservices, where essentially every method is wrapped in a class because it is a self-contained unit. I think the weirdness stems from these scenarios and pollutes design spaces where it shouldn't.

                                        1 Reply Last reply
                                        0
                                        • H honey the codewitch

                                          It was an assignment, I think photocopied out of a book but I didn't ask.

                                          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
                                          #76

                                          honey the codewitch wrote:

                                          It was an assignment, I think photocopied out of a book

                                          So, that means the Professor is just a willing purveyor of tripe who does not take the time to determine if the materials she uses have any value. Also, it means that the Professor is not the root cause of the problem -- just the purveyor. Which, in turn means... We need to get that book and destroy it. :laugh: I'd love to know the title of the book which has : 1. bamboozled the professor 2. is chosen by universities 3. is spreading lies about OOP :rolleyes:

                                          H 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