+------------------------------------------------------------------------------+ | CS100 | | Box Scope Diagram rules | | Modified from Spring 2000 | | (work in progress) | +------------------------------------------------------------------------------+ | Key: | | + main bullet | | - sub bullet | | @ Updated portions 11/13/2000 | | # Unfinished | +------------------------------------------------------------------------------+ General: + the following boxes get drawn at CERTAIN points in the code + changes in later portions of code change the diagram +------------------------------------------------------------------------------+ Boxes: * + indicate the limit of SCOPE * - Scope refers to the visibility of a piece of code * - What the code can, and cannot, access/use + if the calling code cannot find the variable/method/object/class inside the current box, the calling code "looks" outside the current box + if the thing sought after is still not found, the calling code keeps looking at the outer boxes until there no more boxes + usually the search stops at the class box + the location in a certain box indicates an entity's scope +------------------------------------------------------------------------------+ Class: + every class gets a box +------------------------------------------------------------------------------+ Class variable: + gets a box inside the class box + values start off as zero (according to type) + if value changes, cross off the old value and write the new one nearby +------------------------------------------------------------------------------+ Class method: + gets a box inside the class box WHEN the method is activated * + write the method name and input argument variables above the method box + cross off the method when the activation ends + when a the method is called again write a new box for the method to the right * + ultimately, you will not draw method boxes to improve clarity +------------------------------------------------------------------------------+ Object: + Draw a box inside the class when an object is created + the reference variable that refers to the object has an arrow drawn to the object box * + Delete this line: [cross off the object when it is destroyed] * Why? Most of the diagrams we'll have you draw won't correspond to * code that clearly indicates the death of an object. # + Cross off an object for the following conditions:...... +------------------------------------------------------------------------------+ Instance variable: + gets a box inside the object box + values start off as zero (according to type) + if value changes, cross off the old value and write the new one nearby +------------------------------------------------------------------------------+ Instance method: + gets a box inside the object box WHEN the method is activated * + write the method name and input argument variables above the method box + cross off the method when the activation ends + when a the method is called again write a new box for the method to the right * + ultimately, you will not draw method boxes to improve clarity +------------------------------------------------------------------------------+ * Constructor: * + technically, follow the same rules of instance methods * + usually you will not include constructors to ease clarity +------------------------------------------------------------------------------+ Local variable: + gets a box inside a method + has unknown/undetermined values, so write a question mark (?) inside the local-variable box + the collection of variables inside the box for a method is called the ACTIVATION RECORD + cross off arrows of reference variables after method activation ends (see Arrow, below) +------------------------------------------------------------------------------+ * Arrow: * + Draw an arrow to connect a reference variable to an object when an * assignment occurs * + Local variables might also contain references, so they may connect * to objects. Draw arrows unless instructed otherwise: * - for clarity, sometimes we will not draw these arrows for * variables inside methods that finish execution * - methods which we occasionally ignore are setters and getters * + When a connection to an object is lost/terminates, draw an X on * the arrow -- the X indicates you are "crossing off" the arrow # + arrows point (to? from?) variable (to? from?) object +------------------------------------------------------------------------------+ Default values of class and instance variables are zeros: * + char: ASCII Code 0 (ASCII code of 0 is something called NUL PROMPT) + int: 0 + float: 0.0 + double: 0.0 + boolean: false + Object: null + String: null @ What values go in the boxes? @ + Give instance variables a default value @ + If the variable has an initial assignment, [cross off zero and replace @ with value (maybe better to say give the value and skip the zero?)] +------------------------------------------------------------------------------+ * API: * + Builtin methods/variables/classes: * Do not draw boxes unless something your code does creates unique * objects modified by other portions of the code. # + Example: do not draw boxes for System.out.println +------------------------------------------------------------------------------+ * Strings: * + Draw a class box called STRING CLASS * + Draw string literals inside the string-class box * + Arrows point directly to the string literals +------------------------------------------------------------------------------+ # $args$: # TBD +------------------------------------------------------------------------------+ # Inheritance: # TBD +------------------------------------------------------------------------------+ @ Arrays: +------------------------------------------------------------------------------+