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. General Programming
  3. C / C++ / MFC
  4. when to use classes

when to use classes

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
7 Posts 5 Posters 0 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.
  • A Offline
    A Offline
    Archer282
    wrote on last edited by
    #1

    Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?

    C C N V 4 Replies Last reply
    0
    • A Archer282

      Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Archer282 wrote: So can anyone give me some examples of when it would be better to use a class? When you have more than 20 lines of code, you should be using classes. Either you're writing incredibly small and simple programs, or your code is a complete nightmare from a maintenence standpoint. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      C 1 Reply Last reply
      0
      • C Christian Graus

        Archer282 wrote: So can anyone give me some examples of when it would be better to use a class? When you have more than 20 lines of code, you should be using classes. Either you're writing incredibly small and simple programs, or your code is a complete nightmare from a maintenence standpoint. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        C Offline
        C Offline
        cmk
        wrote on last edited by
        #3

        After writing and erasing two lengthy replies (covering the history and philosophy of OO design) i see the merit in your reply. You are very wise. Although, i personally would have said 42 lines ... 42 being THE answer and all. :) ...cmk Save the whales - collect the whole set

        C 1 Reply Last reply
        0
        • A Archer282

          Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?

          C Offline
          C Offline
          cmk
          wrote on last edited by
          #4

          I've been given this fantasitc new 13mm wrench. I know how to use it, but have only done so with 13mm nuts. How do i use it to build a car ? I don't mean to be flipant, but the question begs a reply that covers the whole of the object oriented design paradigm. A topic too large to fit in a reply. Start by reading up on object oriented design. Follow up by taking some small procedural programs you may have written and see if you can port some of the code into classes. The trick is to start seeing your program designs as the interaction of objects, as opposed to the paths of code execution. Wherever you see an 'object', you have a class waiting to be born. ...cmk Save the whales - collect the whole set

          1 Reply Last reply
          0
          • A Archer282

            Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?

            N Offline
            N Offline
            Neelesh K J Jain
            wrote on last edited by
            #5

            When to use Classess? What type of classes do u want to use. Ok whenever u want to do some socket programming then u have to derive it from socket class. Everything is depend on the situation. Thats is a other matter that u want to go for classes or not. But OO provides the class concept which is one of the beautiful thing. Neelesh Jain. Work Hard and A Bit of LUCK is KEY to SUCCESS.

            1 Reply Last reply
            0
            • A Archer282

              Okay, i know what classes are, i know how to make them, i just dont know when to implement them in my programs. i hardly ever use a class unless im doing something with MFC. So can anyone give me some examples of when it would be better to use a class?

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

              You use classes to "group" logical pieces of code together. example: You have a class car. This class has several properties like maximum speed, color, type, ... and this car can do stuff like drive, turn right and (hopefully) left, brake, ... now typically your properties are your variables; so you would have a string type, double maxspeed, string color, ... The things your class can do are your functions. so void Drive(){ ... }, void TurnLeft(){...} and so on. So far your with me I hope. Now if you've encapsulated your class you can call this class somewhere else. So you make another class like racetrack in this class you can call as many instances of your carclass as you like. each instance with his own properties... so in ractrack you declare: Car Porsche = new Car(); Car Volvo = new Car(); .... now you can set properties: Porsche.MaxSpeed = 320; // km/h Volvo.MaxSpeed = 160; // km/h (note: you have to know you public/private/protected...) this is just a simple example, but I hope I've made it a bit more clear for you. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

              1 Reply Last reply
              0
              • C cmk

                After writing and erasing two lengthy replies (covering the history and philosophy of OO design) i see the merit in your reply. You are very wise. Although, i personally would have said 42 lines ... 42 being THE answer and all. :) ...cmk Save the whales - collect the whole set

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                ROTFL - brilliant. I can't wait to hear the new HHGTTG episodes. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                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