I have the timer control call Signal.NextState where Signal is an object of type Traffic Light. The Traffic Light class has a NextState method which checks the current state and changes the light and returns a new timer interval.
I'm thinking I can use the traffic light class more or less as I have it now with my freshmen so they can learn about the timer. I may have my sophomores create the Traffic Light class. The classes I created are written in C#. That means I can use them as the basis for my examples for the sophomores.
Since it is all .NET I can use the C# objects in Visual Basic programs. That means I can hide the complicated stuff from the beginners who are not ready for it. We can stick with just using the timer. Or I can create a version that doesn’t do the state work inside the traffic light control. That way I can talk about state programming and still hide a lot of things.
If I take the later path I can show my students who take the second course how we can encapsulate this sort of thing. We’ll see. I have a lot more thinking to do about this whole thing. But having some code to play with helps me work things out.
Edit: Dan Schellenberg has his own riff on this project and blogged about it at Traffic Light Remix
2 comments:
Thanks for passing along the idea, Alfred. I used a version of this with my class today, to reinforce state variables. I wrote a bit about it here:
http://dan.schellenbergs.ca/2016/02/29/traffic-light-remix/
Though I haven't gotten to OOP with these students yet, it might be an interesting thing to covert to OOP once we get there...
Great post Dan. This is exactly to sort of thing I always hope to see from sharing ideas. Each person makes it their own and adds something new. Thanks for sharing.
Post a Comment