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. Design and Architecture
  4. UML state diagrams

UML state diagrams

Scheduled Pinned Locked Moved Design and Architecture
questionhelp
5 Posts 3 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.
  • P Offline
    P Offline
    Phil005
    wrote on last edited by
    #1

    Hi! I'm new to this forum, so I say hello to everyone! My question about state diagram is about object states. How are they represented in code? Are those methods or something else? And I have another question about operations. Are operations methods? I didnt find many pages on google concerning these things so I decided to ask on this forum. Thank you for your help!

    G K 2 Replies Last reply
    0
    • P Phil005

      Hi! I'm new to this forum, so I say hello to everyone! My question about state diagram is about object states. How are they represented in code? Are those methods or something else? And I have another question about operations. Are operations methods? I didnt find many pages on google concerning these things so I decided to ask on this forum. Thank you for your help!

      G Offline
      G Offline
      Gerben Jongerius
      wrote on last edited by
      #2

      A state diagram describes the state your program or a sub section of the program is in. So the implementation of a state diagram could be anywhere and everywhere, sorry to be so unspecific. If your state is specific to one class in the entire application it could be a big switch or if block in the controller for that specific class, think about a car where you have an engine management class responsible for changing gears. The EngineManagement class could contain the switch or if block where each state calls different methods on the GearSystem and Throttle classes. Also read up on the 'Software Implementations' section on the Finate-State machine, this describes with some examples on how you could implement a state diagram.

      P 1 Reply Last reply
      0
      • G Gerben Jongerius

        A state diagram describes the state your program or a sub section of the program is in. So the implementation of a state diagram could be anywhere and everywhere, sorry to be so unspecific. If your state is specific to one class in the entire application it could be a big switch or if block in the controller for that specific class, think about a car where you have an engine management class responsible for changing gears. The EngineManagement class could contain the switch or if block where each state calls different methods on the GearSystem and Throttle classes. Also read up on the 'Software Implementations' section on the Finate-State machine, this describes with some examples on how you could implement a state diagram.

        P Offline
        P Offline
        Phil005
        wrote on last edited by
        #3

        Ok! Thank you for your help!

        1 Reply Last reply
        0
        • P Phil005

          Hi! I'm new to this forum, so I say hello to everyone! My question about state diagram is about object states. How are they represented in code? Are those methods or something else? And I have another question about operations. Are operations methods? I didnt find many pages on google concerning these things so I decided to ask on this forum. Thank you for your help!

          K Offline
          K Offline
          Keld Olykke
          wrote on last edited by
          #4

          Take a look at this. If this is the type of state diagrams you are talking about then you can make 1 type of implementation as follows in code: 1) Create a class e.g. MyState. 2) Add a string property State with a private setter and a public getter. 3) Add a public transition method e.g. Transition that takes an argument e.g. Target 4) Let the transition method set property State to Target. If you instantiate MyState, you have the means to encapsulate a state diagram into an object. Identify the transitions in other code and let those transitions call Transition of MyState. In this setup you have a state object that is able to report the state of others. Sometimes you see MyState as a property on another object. Sometimes MyState is just part of another object. The later means that an object e.g. MyFoo encapsulates its own state information, which is quite a virtue in OOP. Example: As a OOP developer you expect that a File object is able to tell if its read-only or closed. You don't want to shop around by other objects to figure that out. If MyFoo not only encapsulates its state information, but also its state transitions, then MyFoo becomes quite handsome. In this case the Transit method must implement all possible transitions with their conditions and throw an exceptions (or similar), if it cannot make a transition. If you let MyFoo make some transitions by it self then it becomes partly autonomous. If MyFoo becomes 100% autonomous then make the transition method private. Usually the Transition method is a set of methods e.g. File.Open, File.Close, etc. Usually the State property is an enum or similar. Some OOPs prefer however the State pattern. Regards, Keld

          P 1 Reply Last reply
          0
          • K Keld Olykke

            Take a look at this. If this is the type of state diagrams you are talking about then you can make 1 type of implementation as follows in code: 1) Create a class e.g. MyState. 2) Add a string property State with a private setter and a public getter. 3) Add a public transition method e.g. Transition that takes an argument e.g. Target 4) Let the transition method set property State to Target. If you instantiate MyState, you have the means to encapsulate a state diagram into an object. Identify the transitions in other code and let those transitions call Transition of MyState. In this setup you have a state object that is able to report the state of others. Sometimes you see MyState as a property on another object. Sometimes MyState is just part of another object. The later means that an object e.g. MyFoo encapsulates its own state information, which is quite a virtue in OOP. Example: As a OOP developer you expect that a File object is able to tell if its read-only or closed. You don't want to shop around by other objects to figure that out. If MyFoo not only encapsulates its state information, but also its state transitions, then MyFoo becomes quite handsome. In this case the Transit method must implement all possible transitions with their conditions and throw an exceptions (or similar), if it cannot make a transition. If you let MyFoo make some transitions by it self then it becomes partly autonomous. If MyFoo becomes 100% autonomous then make the transition method private. Usually the Transition method is a set of methods e.g. File.Open, File.Close, etc. Usually the State property is an enum or similar. Some OOPs prefer however the State pattern. Regards, Keld

            P Offline
            P Offline
            Phil005
            wrote on last edited by
            #5

            Thats's great. Thank you for the post!

            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