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. C++ and states

C++ and states

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
8 Posts 4 Posters 1 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.
  • V Offline
    V Offline
    vikramlinux
    wrote on last edited by
    #1

    Can we say that class/objects in C++ implicitly supports state based programmming?

    C 1 Reply Last reply
    0
    • V vikramlinux

      Can we say that class/objects in C++ implicitly supports state based programmming?

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      What do you mean exactly ? Can you be more specific ? You still can have a kind of 'state machine' in a class if you want to. I don't really understand what you are asking for.

      V 1 Reply Last reply
      0
      • C Cedric Moonen

        What do you mean exactly ? Can you be more specific ? You still can have a kind of 'state machine' in a class if you want to. I don't really understand what you are asking for.

        V Offline
        V Offline
        vikramlinux
        wrote on last edited by
        #3

        well let me explain, Say I have a class Class SunLight{ public: bool state; void set_state(bool state_value) { state=state_value; } }; Here I am have function which changes the data member value of my class. So in general I am changing the state of my class. in C language I can do same using procedure programming but where I need to explicly declare and hold/preserve variables and manuipulate by passing those variables to function.I think this extra burden on programmer. finally Such kind of implementation can ne implemented as shown above in C++ using classes. So can we say that for state based system my class are useful and efficient, hence the argument "C++ classes implicilty supports state based programming". -- modified at 4:54 Friday 21st April, 2006

        C T 2 Replies Last reply
        0
        • V vikramlinux

          well let me explain, Say I have a class Class SunLight{ public: bool state; void set_state(bool state_value) { state=state_value; } }; Here I am have function which changes the data member value of my class. So in general I am changing the state of my class. in C language I can do same using procedure programming but where I need to explicly declare and hold/preserve variables and manuipulate by passing those variables to function.I think this extra burden on programmer. finally Such kind of implementation can ne implemented as shown above in C++ using classes. So can we say that for state based system my class are useful and efficient, hence the argument "C++ classes implicilty supports state based programming". -- modified at 4:54 Friday 21st April, 2006

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          I think you answered your own question ;) Anyway what a complicated way of seeing things.

          vikrams wrote:

          C++ classes implicilty supports state based programming

          A lot of words for a simple concept. You should consider reconverting you in management :-D (no offense, this is just a joke ;) ).

          V 1 Reply Last reply
          0
          • C Cedric Moonen

            I think you answered your own question ;) Anyway what a complicated way of seeing things.

            vikrams wrote:

            C++ classes implicilty supports state based programming

            A lot of words for a simple concept. You should consider reconverting you in management :-D (no offense, this is just a joke ;) ).

            V Offline
            V Offline
            vikramlinux
            wrote on last edited by
            #5

            My sole intension was to validate the thing I put here...If there is any conceptual missunderstanding , u may please state here.

            C 1 Reply Last reply
            0
            • V vikramlinux

              well let me explain, Say I have a class Class SunLight{ public: bool state; void set_state(bool state_value) { state=state_value; } }; Here I am have function which changes the data member value of my class. So in general I am changing the state of my class. in C language I can do same using procedure programming but where I need to explicly declare and hold/preserve variables and manuipulate by passing those variables to function.I think this extra burden on programmer. finally Such kind of implementation can ne implemented as shown above in C++ using classes. So can we say that for state based system my class are useful and efficient, hence the argument "C++ classes implicilty supports state based programming". -- modified at 4:54 Friday 21st April, 2006

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              i still don't understand the whole thing you expllain/ask for (if ever), but if you use a bool, then your object will have only 2 states : ON/OFF, enabled/disabled, true/false... so, i'd suggest you (once you"ll need to emulate a much bigger state machine), to use an enum which defines one flag per state...

              N 1 Reply Last reply
              0
              • V vikramlinux

                My sole intension was to validate the thing I put here...If there is any conceptual missunderstanding , u may please state here.

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                You can see things as 'encapsulation' also: it is a little bit the same concept. Each object retains its state (that is not directly accessible for the external world) and you can modify it by the use og public functions. I think it's the same as what you said.

                1 Reply Last reply
                0
                • T toxcct

                  i still don't understand the whole thing you expllain/ask for (if ever), but if you use a bool, then your object will have only 2 states : ON/OFF, enabled/disabled, true/false... so, i'd suggest you (once you"ll need to emulate a much bigger state machine), to use an enum which defines one flag per state...

                  N Offline
                  N Offline
                  Nick_Kisialiou
                  wrote on last edited by
                  #8

                  ... or use the "state design pattern", which can be implemented in any OO language.

                  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