Scratch Sprites - What should init do?

The Obvious

In the previous section I decided that I felt that the following were the "obvious" data that we stored about each sprite. 

So what is the default value of each of these?

Five of these six values have easy defaults.  Each of the number has a CLEAR default when a new version is made:

The only one that we can't easily default is the name. 

Scratch itself give it a name and will automatically add a number to this if you have more than one of the same "kind"  [eg. Cloud, Cloud2, Cloud3, etc]  This is done through the use of a special kind of "class variable" which is different from the "instance variables" we are discussing.  We won't actually look at how to solve this in Python.  Instead, we will just make the decision that the name must be provided by the creator.  This is similar to what we talked about with the CreditCard class.  We said that the balance can start at zero by default but the owner MUST be provided when a new instance is created.

 

Class Diagrams

When instances of  a class get their values from the init function (aka the constructor) we normally include that information in the class diagram. Thus, the new and improved class diagram might look like this: