Diagramming Conventions
You are already familiar with most of diagramming conventions from Assignment 2. Our new conventions build on top of these. All of our examples below use the following class definition.
class Example(object):
CONST=3
def __init__(self):
pass
def foo(self):
return 42
The line numbers to the left are used in the method call frames, just as in Assignment 2.
Diagramming Class Folders
When you define a class, Python creates a special folder called a class folder that stores the information about that class. Technically, Python also creates a global variable with the same name as the class and puts the name of that folder in the global variable; that is what you see when you put the class above in the Python Tutor.
To simplify things, we do not want you to show the variable in global space (just like we never ask you to show the variable for a function name in global space). We just want you to create a folder in the heap, and put the name of the class in the tab. We also want you to put the tab on the right so that we can tell this is a class folder. This is illustrated below.
The class folder contains all the methods and any class attributes. In a class definition, any assignment statement outside of a method definition creates a class attribute. In the example above, CONST is a class attribute.
Technically, the methods are also variables themselves. This is what you would see if you used the Python visualizer. However, the contents of this variable are really complicated, and the Python visualizer just writes the method header (the name plus all of its parameters) as its value. Therefore, that is what we want you to write for the methods in a class: the method header (without the def).
The example above works when the class is a base class (e.g. a subclass of class object). Suppose we have a class that is a subclass of a user-defined class, like the example Demo below.
class Demo(Example):
pass
We want to indicate this relationship in our class folders. To do this, we put the name of the parent class in parentheses, as shown below. Note that this class has no methods or class attributes in it, because there are none in the class definition.
Diagramming Object Folders
A object is an instance of a class. While there is only one class Example, there may be more than one Example object. Each time you call the constructor, you create a new object. For example, suppose we execute the following statements:
>>> e = Example()
>>> e.x = 10
The constructor for Example creates an empty folder (why?), while the second assignment statement adds an attribute x to the folder. The end result is as follows:
The instance folder only contains attributes added to the instance. It does not contain class attributes, and (for this course) it never contains methods.
Diagramming Method Calls
A method class works almost exactly like a function call. You create the call frame, and plug the arguments into the parameters. You then execute each line in the method, changing the call frame as necessary. Finally, you erase the frame.
The only real difference is the function name that goes in the upper left box. We want both the name of the class and the method name in this box. For example. for the method call
>>> e.foo()
the initial diagram for the call frame is as follows
Note the name is not foo in the top left folder, but Example.foo<. That tells us to use the version of foo that is stored in the class folder Example.
Diagramming Constructor Calls
A constructor is just a function, so Python should create a call frame when it is called. However, this function is built-in, so we do not really know what it looks like. You will notice that the Python visualizer does not create a call frame for the constructor either. However, it does create a call frame for the initializer __init__, which the constructor uses as a helper.
We are going to do it the way that the Python visualizer does it. Remember the 4 steps of a constructor call:
1. It creates a new empty folder of that class.
2. It puts the folder into the heap</li>
3. It executes the method __init__ (creating a call frame)</li>
4. It returns the folder name
In our diagram, we combine steps 1 and 2 (because otherwise we do not know where to put the folder). We also combine step 4 with the erasing step of __init__ even though __init__ has no return variable. For example, if we executed the constructor
Diagramming Conventions
You are already familiar with most of diagramming conventions from Assignment 2. Our new conventions build on top of these. All of our examples below use the following class definition.
class Example(object):
CONST=3
def __init__(self):
pass
def foo(self):
return 42
The line numbers to the left are used in the method call frames, just as in Assignment 2.
Diagramming Class Folders
When you define a class, Python creates a special folder called a class folder that stores the information about that class. Technically, Python also creates a global variable with the same name as the class and puts the name of that folder in the global variable; that is what you see when you put the class above in the Python Tutor.
To simplify things, we do not want you to show the variable in global space (just like we never ask you to show the variable for a function name in global space). We just want you create a folder in the heap, and put the name of the class in the tab. We also want you to put the tab on the right so that we can tell this is a class folder. This is illustrated below.
The class folder contains all the methods and any class attributes. In a class definition, any assignment statement outside of a method definition creates a class attribute. In the example above, CONST is a class attribute.
Technically, the methods are also variables themselves. This is what you would see if you used the Python visualizer. However, the contents of this variable are really complicated, and the Python visualizer just writes the method header (the name plus all of its parameters) as its value. Therefore, that is what we want you to write for the methods in a class: the method header (without the def).
The example above works when the class is a base class (e.g. a subclass of class object). Suppose we have a class that is a subclass of a user-defined class, like the example Demo below.
class Demo(Example):
pass
We want to indicate this relationship in our class folders. To do this, we put the name of the parent class in parentheses, as shown below. Note that this class has no methods or class attributes in it, because there are none in the class definition.
Diagramming Object Folders
A object is instance of a class. While there is only one class Example, there may be more than one Example object. Each time you call the constructor, you create a new object. For example, suppose we execute the following statements:
>>> e = Example()
>>> e.x = 10
The constructor for Example creates an empty folder (why?), while the second assignment statement adds an attribute x to the folder. The end result is as follows:
The instance folder only contains attributes added to the instance. It does not contain class attributes, and (for this course) it never contains methods.
Diagramming Method Calls
A method class works almost exactly like a function call. You create the call frame, and plug the arguments into the parameters. You then execute each line in the method, changing the call frame as necessary. Finally, you erase the frame.
The only real difference is the function name that goes in the upper left box. We want both the name of the class and the method name in this box. For example. for the method call
>>> e.foo()
the initial diagram for the call frame is as follows
Note the name is not foo in the top left folder, but Example.foo<. That tells us to use the version of foo that is stored in the class folder Example.
Diagramming Constructor Calls
A constructor is just a function, so Python should create a call frame when it is called. However, this function is built-in, so we do not really know what it looks like. You will notice that the Python visualizer does not create a call frame for the constructor either. However, it does create a call frame for the initializer __init__, which the constructor uses as a helper.
We are going to do it the way that the Python visualizer does it. Remember the 4 steps of a constructor call:
1. It creates a new empty folder of that class.
2. It puts the folder into the heap</li>
3. It executes the method __init__ (creating a call frame)</li>
4. It returns the folder name
In our diagram, we combine steps 1 and 2 (because otherwise we do not know where to put the folder). We also combine step 4 with the erasing step of __init__ even though __init__ has no return variable. For example, if we executed the constructor
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme