211 Procedural comparison
In the light switch example, what variable represents the state of the light switch?
What is meant by behaviour in the context of the procedural light switch example?
Why is it necessary to use two separate functions ,
(turnOn()
andturnOff()
, in the procedural version of the light switch?
What is the initial state of the light switch when it comes from the factory, according to the example? How is this represented in code?
What limitations would you encounter if you wanted to use this procedural code to model multiple light switches?
How does the use of a global variable affect the flexibility of the procedural code?
Imagine you wanted to add a new function to the procedural light switch code to toggle the switch (switch from on to off or off to on). How might you write that function?
How might combining the state and behaviour of the light switch into one structure (like a class) solve the limitations you identified?
Last updated
Was this helpful?