C++ and states
-
Can we say that class/objects in C++ implicitly supports state based programmming?
-
Can we say that class/objects in C++ implicitly supports state based programmming?
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.
-
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.
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
-
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
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 ;) ).
-
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 ;) ).
My sole intension was to validate the thing I put here...If there is any conceptual missunderstanding , u may please state here.
-
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
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...
-
My sole intension was to validate the thing I put here...If there is any conceptual missunderstanding , u may please state here.
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.
-
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...
... or use the "state design pattern", which can be implemented in any OO language.