Why not have the context class inherit from the application class?
Because: • SMC is designed to be as loosely-coupled with your application code as possible. The SMC Programmer’s Manual section 3 shows just how little code it takes to hook an SMC-generated state machine into your class. • Robert Martin’s FSM pattern is not as loosely-coupled as I would like. With Robert Martin’s pattern, you write the Turnstile class and and then have AppClassFSM inherit from Turnstile. You then instantiate the TurnstileFSM class and work with that object. I think this is unnatural. My inclination is to instantiate Turnstile because that is what corresponds to the “real” world. SMC does a variation on this theme. It generates a TurnstileContext class which inherits from FSMContext class and keeps a reference to the Turnstile object which instantiated it. TurnstileContext stores the current state and defines the “transition” methods which Turnstile calls when it issues a transition. For a more detailed explanation of what patterns SMC uses, see the SMC Programmer’s Ma
Related Questions
- handles a special class of APIs used in the application code according to the system-level context. See What Is Context-Sensitive Generation?.
- What does class division mean, found in the ENCS assessment form in the on-line admission application?
- Why not have the context class inherit from the application class?