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 3 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 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
    JeffL45
    wrote on last edited by
    #45

    Many people consider this a must read for OOP/class deisgn -

    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

      G Offline
      G Offline
      Gary Wheeler
      wrote on last edited by
      #46

      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 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
        MikeCO10
        wrote on last edited by
        #47

        No, you are correct. Your car is a valid class as you define it. ReadTextFile() is a function. To be a valid class, imo, it would be TextFile as the class, with properties and actions. TextFile.length, etc. and TextFile.Read,write,etc. My take, in English grammar, is that a class should be a noun, with adjectives, verbs and possibly adverbs that go with it. If it's short of that, it deserves another look for consideration as a function or structure. I suppose, depending on the language, a class could be looked at as a convenient way to store a reusable. What a declaration nightmare that creates, using your example.

        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

          B Offline
          B Offline
          BryanFazekas
          wrote on last edited by
          #48

          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.

          You're right. A class encapsulate a physical or logical object, including ways to interact with the object. What that professor is teaching is sheer idiocy. Many moons ago a friend relayed a story -- we worked for a consulting firm and he did the tech interview for a professor that had taught VB at the local community college for 5 years. She failed the interview and he recommended against hiring her. Why? She knew the syntax of the language better than he did, but she had NO idea how to actually program. She could answer questions such as "which method to use to add an item to a listbox" (something we didn't bother asking), but didn't know which construct to use for looping. She could write an if loop, but couldn't tell when to use if or while or foreach. He went into the interview assuming it was a formality, and ended up vetoing her. Far too many college professors have no real world experience.

          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

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

            But he explained OOP that way and the implmentation in C++ was that way as well.

            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.

            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
              Daniel Anderson 2021
              wrote on last edited by
              #50

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

                D Offline
                D Offline
                DougInNC2
                wrote on last edited by
                #51

                0x01AA wrote:

                Abstracting the reality is usually very hard.

                Abstracting reality may be difficult but its absolutely essential. If you see a chair that you've never seen before and you don't have an abstract concept of what a chair is, how would you ever know its a chair? It sounds like this professor had a difficult time with the abstract concept of a class. It can be a difficult concept but I would think it would be a prerequisite to being an IT professor. But what do I know? I'm self taught and assume there a plenty of abstract concepts I'm just not aware of.

                1 Reply 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

                  O Offline
                  O Offline
                  obermd
                  wrote on last edited by
                  #52

                  I would say TextReader is the superclass of ReadTextFile. Text doesn't always come in files.

                  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

                    J Offline
                    J Offline
                    jochance
                    wrote on last edited by
                    #53

                    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 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
                      Member_5893260
                      wrote on last edited by
                      #54

                      Well, at least we'll never be unemployed!

                      A 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
                        Dave B 68
                        wrote on last edited by
                        #55

                        Why does it have to be one or the other? One class could model a physical object like a car while another could model an operation such as a database transaction, file operation, or something more complex. At the end of the day it is about using the tools to minimize the cost of solving problems. And concepts like encapsulation and polymorphism frequently are the best tools for the job.

                        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

                          K Offline
                          K Offline
                          klinkenbecker
                          wrote on last edited by
                          #56

                          To a large extent the 'normalization' of classes is akin to the normalization of data records. The atomic characteristics of a class, that would drive application decomposition (and vice versa), can vary between applications. Thus a useful class decomposition in one instance can be a dogs breakfast in another. There is a similar problem when looking at communications protocols - doctrine dictates multiple layers but these can severely impede and bloat small systems. As humans show every moment, it is possible to communicate without layers (with varying degrees of success), particularly when context is available. For humans effective communication is possible even when the context is ambiguous. For myself, I have classes that do the equivalent of 'ReadTextFile' or 'ReadComPort' - these typically act as base class for different types of parser such that the data is transformed in some way into an easily digestible form for another part of the app. Whereas one may aspire to a 'universal' set of pattern classes, their utility will generally boil down to adaptation within specific application constraints.

                          1 Reply Last reply
                          0
                          • 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
                                          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